diff options
Diffstat (limited to 'server/lib/cache/abstract-video-static-file-cache.ts')
-rw-r--r-- | server/lib/cache/abstract-video-static-file-cache.ts | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/server/lib/cache/abstract-video-static-file-cache.ts b/server/lib/cache/abstract-video-static-file-cache.ts index 7eeeb6b3a..8e895cc82 100644 --- a/server/lib/cache/abstract-video-static-file-cache.ts +++ b/server/lib/cache/abstract-video-static-file-cache.ts | |||
@@ -1,12 +1,9 @@ | |||
1 | import * as AsyncLRU from 'async-lru' | 1 | import * as AsyncLRU from 'async-lru' |
2 | import { createWriteStream } from 'fs' | 2 | import { createWriteStream } from 'fs' |
3 | import { join } from 'path' | ||
4 | import { unlinkPromise } from '../../helpers/core-utils' | 3 | import { unlinkPromise } from '../../helpers/core-utils' |
5 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
6 | import { CACHE, CONFIG } from '../../initializers' | ||
7 | import { VideoModel } from '../../models/video/video' | 5 | import { VideoModel } from '../../models/video/video' |
8 | import { fetchRemoteVideoStaticFile } from '../activitypub' | 6 | import { fetchRemoteVideoStaticFile } from '../activitypub' |
9 | import { VideoCaptionModel } from '../../models/video/video-caption' | ||
10 | 7 | ||
11 | export abstract class AbstractVideoStaticFileCache <T> { | 8 | export abstract class AbstractVideoStaticFileCache <T> { |
12 | 9 | ||
@@ -17,9 +14,10 @@ export abstract class AbstractVideoStaticFileCache <T> { | |||
17 | // Load and save the remote file, then return the local path from filesystem | 14 | // Load and save the remote file, then return the local path from filesystem |
18 | protected abstract loadRemoteFile (key: string): Promise<string> | 15 | protected abstract loadRemoteFile (key: string): Promise<string> |
19 | 16 | ||
20 | init (max: number) { | 17 | init (max: number, maxAge: number) { |
21 | this.lru = new AsyncLRU({ | 18 | this.lru = new AsyncLRU({ |
22 | max, | 19 | max, |
20 | maxAge, | ||
23 | load: (key, cb) => { | 21 | load: (key, cb) => { |
24 | this.loadRemoteFile(key) | 22 | this.loadRemoteFile(key) |
25 | .then(res => cb(null, res)) | 23 | .then(res => cb(null, res)) |
@@ -28,7 +26,8 @@ export abstract class AbstractVideoStaticFileCache <T> { | |||
28 | }) | 26 | }) |
29 | 27 | ||
30 | this.lru.on('evict', (obj: { key: string, value: string }) => { | 28 | this.lru.on('evict', (obj: { key: string, value: string }) => { |
31 | unlinkPromise(obj.value).then(() => logger.debug('%s evicted from %s', obj.value, this.constructor.name)) | 29 | unlinkPromise(obj.value) |
30 | .then(() => logger.debug('%s evicted from %s', obj.value, this.constructor.name)) | ||
32 | }) | 31 | }) |
33 | } | 32 | } |
34 | 33 | ||