refactor: SimpleDataStore.STRATEGIES

This commit is contained in:
Bobby Wibowo 2022-07-03 11:08:00 +07:00
parent 39aaa25f3f
commit d31181b4be
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
3 changed files with 9 additions and 8 deletions

View File

@ -44,18 +44,18 @@ module.exports = {
as it would otherwise have to query database every single time. as it would otherwise have to query database every single time.
If enabled, but "contentDispositionOptions" is missing, it will use these defaults: If enabled, but "contentDispositionOptions" is missing, it will use these defaults:
{ limit: 50, strategy: 'lastGetTime' } { limit: 50, strategy: 'LAST_GET_TIME' }
*/ */
setContentDisposition: false, setContentDisposition: false,
contentDispositionOptions: { contentDispositionOptions: {
limit: 50, limit: 50,
/* /*
Available strategies: lastGetTime, getsCount Available strategies: LAST_GET_TIME, GETS_COUNT
lastGetTime: when cache store exceeds limit, remove cache with oldest access time LAST_GET_TIME: when cache store exceeds limit, remove cache with oldest access time
getsCount: when cache store exceeds limit, remove cache with fewest access count GETS_COUNT: when cache store exceeds limit, remove cache with fewest access count
*/ */
strategy: 'lastGetTime' strategy: 'LAST_GET_TIME'
}, },
/* /*

View File

@ -1,6 +1,6 @@
const STRATEGIES = [ const STRATEGIES = [
'lastGetTime', 'LAST_GET_TIME',
'getsCount' 'GETS_COUNT'
] ]
class SimpleDataStore { class SimpleDataStore {
@ -122,3 +122,4 @@ class SimpleDataStore {
} }
module.exports = SimpleDataStore module.exports = SimpleDataStore
module.exports.STRATEGIES = STRATEGIES

View File

@ -143,7 +143,7 @@ const initServeStaticUploads = (opts = {}) => {
utils.contentDispositionStore = new SimpleDataStore( utils.contentDispositionStore = new SimpleDataStore(
config.contentDispositionOptions || { config.contentDispositionOptions || {
limit: 50, limit: 50,
strategy: 'lastGetTime' strategy: SimpleDataStore.STRATEGIES[0]
} }
) )
opts.preSetHeaders = async (res, req, path, stat) => { opts.preSetHeaders = async (res, req, path, stat) => {