Skip to content

Commit 115919f

Browse files
committed
feat(executor): optional cache for getRuleLog
1 parent b783954 commit 115919f

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

lib/Services/executor.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,34 @@ class Executor {
108108
}
109109

110110
/**
111-
* @param {String} ruleLogId The id of the rule log item to get
112-
* @param {String} userId The user id
111+
* @param {String} ruleLogId The id of the rule log item to get
112+
* @param {String} userId The user id
113+
* @param {Objet} [opts={}] Additional options
114+
* @param {Boolean} [opts.useCache=false] If cached result should be retrieved
115+
* @param {Boolean} [opts.cacheOnNotFound=false] Whether to cache if a 404 error is returned
116+
*
113117
* @returns {Promise}
114118
*/
115-
getRuleLog(ruleLogId, userId) {
119+
getRuleLog(ruleLogId, userId, opts) {
120+
opts = { useCache: false, cacheOnNotFound: false, ...opts };
121+
116122
const url = `${this.url}/rule-logs/${ruleLogId}`;
117123
const query = { user_id: userId };
118124

119-
return this.auth.send(this.service, 'GET', url, { query });
125+
return this.auth.send(this.service, 'GET', url, {
126+
query,
127+
cache: opts.useCache
128+
? {
129+
key: this.auth.genCacheKey(
130+
this.service,
131+
this.getRuleLog.name,
132+
...arguments
133+
),
134+
action: this.auth.cache.actions.get,
135+
onNotFound: opts.cacheOnNotFound
136+
}
137+
: false
138+
});
120139
}
121140

122141
/**

0 commit comments

Comments
 (0)