Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mojaloop/#3885): extend fxquote functionality to persistant mode #348

Merged
merged 11 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ x-depends-on: &dependsOnMysqlAndKafka
condition: service_completed_successfully

x-quoting-service: &quotingServiceBase
image: mojaloop/quoting-service:local
build:
context: .
cache_from:
Expand Down Expand Up @@ -63,7 +64,7 @@ services:


central-ledger:
image: mojaloop/central-ledger:v17.7.0-snapshot.20
image: mojaloop/central-ledger:v17.8.0-snapshot.7
container_name: qs_central-ledger
ports:
- "3001:3001"
Expand Down
8 changes: 8 additions & 0 deletions docker/central-ledger/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
}
}
},
"PROXY_CACHE": {
"enabled": false,
"type": "redis",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we use redis-cluster as it's default proxyCache type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me do that in a follow up PR. I didn't want to touch the int harness.

"proxyConfig": {
"host": "localhost",
"port": 6379
}
},
"PARTICIPANT_INITIAL_POSITION": 0,
"HUB_PARTICIPANT": {
"ID": 1,
Expand Down
15 changes: 8 additions & 7 deletions src/data/cachedDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,22 @@
--------------
******/

const util = require('util')
const Database = require('./database.js')
const Cache = require('memory-cache').Cache
const ErrorHandler = require('@mojaloop/central-services-error-handling')
const Metrics = require('@mojaloop/central-services-metrics')

const { getStackOrInspect } = require('../lib/util')
const { loggerFactory } = require('../lib/index.js')

/**
* An extension of the Database class that caches enum values in memory
*/
class CachedDatabase extends Database {
constructor (config) {
constructor (config, logger) {
super(config)

this.log = logger || loggerFactory({
context: this.constructor.name
})
this.cache = new Cache()
}

Expand Down Expand Up @@ -112,7 +113,7 @@ class CachedDatabase extends Database {

if (!value) {
// we need to get the value from the db and cache it
this.writeLog(`Cache miss for ${type}: ${util.inspect(params)}`)
this.log.debug('Cache miss for: ', { type, params })
value = await super[type].apply(this, params)
// cache participant with a shorter TTL than enums (participant data is more likely to change)
if (
Expand All @@ -126,13 +127,13 @@ class CachedDatabase extends Database {
}
histTimer({ success: true, queryName: type, hit: false })
} else {
this.writeLog(`Cache hit for ${type} ${util.inspect(params)}: ${value}`)
this.log.error('Cache hit for : ', { type, params, value })
histTimer({ success: true, queryName: type, hit: true })
}

return value
} catch (err) {
this.writeLog(`Error in getCacheValue: ${getStackOrInspect(err)}`)
this.log.error('Error in getCacheValue: ', err)
histTimer({ success: false, queryName: type, hit: false })
throw ErrorHandler.Factory.reformatFSPIOPError(err)
}
Expand Down
Loading