@things-factory/cache-service 8.0.0-alpha.21 → 8.0.0-alpha.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/cache-service",
3
- "version": "8.0.0-alpha.21",
3
+ "version": "8.0.0-alpha.24",
4
4
  "main": "dist-server/index.js",
5
5
  "things-factory": true,
6
6
  "license": "MIT",
@@ -25,10 +25,10 @@
25
25
  "dependencies": {
26
26
  "@operato/graphql": "^8.0.0-alpha",
27
27
  "@operato/shell": "^8.0.0-alpha",
28
- "@things-factory/auth-base": "^8.0.0-alpha.19",
29
- "@things-factory/shell": "^8.0.0-alpha.19",
28
+ "@things-factory/auth-base": "^8.0.0-alpha.24",
29
+ "@things-factory/shell": "^8.0.0-alpha.22",
30
30
  "object-hash": "^3.0.0",
31
31
  "redis": "^4.6.14"
32
32
  },
33
- "gitHead": "788bc537e525825b775bcedea2394e39e9222ef2"
33
+ "gitHead": "934692cc70c308351f4d3f720a26aed295d14486"
34
34
  }
@@ -2,7 +2,8 @@ import { ICacheService } from './types'
2
2
  import { config } from '@things-factory/env'
3
3
 
4
4
  const cacheConfig = config.get('cache', {
5
- middleware: 'database'
5
+ middleware: 'database',
6
+ autoClearStale: true
6
7
  })
7
8
 
8
9
  const { CacheServiceDatabase } = require('./cache-service-database')
@@ -11,23 +12,27 @@ const { CacheServiceRedis } = require('./cache-service-redis')
11
12
  export const cacheService: ICacheService =
12
13
  cacheConfig.middleware == 'redis' ? new CacheServiceRedis() : new CacheServiceDatabase()
13
14
 
14
- setTimeout(async () => {
15
- try {
16
- const count = await cacheService.clearStaleCache()
17
- console.info('Successfully cleared: ', count, ' stale cache entries')
18
- } catch (err) {
19
- console.error('An error occurred while clearing stale cache:', err)
20
- }
21
- }, 60 * 1000)
15
+ export function autoClearStale() {
16
+ if (cacheConfig.autoClearStale) {
17
+ setTimeout(async () => {
18
+ try {
19
+ const count = await cacheService.clearStaleCache()
20
+ console.info('Successfully cleared: ', count, ' stale cache entries')
21
+ } catch (err) {
22
+ console.error('An error occurred while clearing stale cache:', err)
23
+ }
24
+ }, 60 * 1000)
22
25
 
23
- setInterval(
24
- async () => {
25
- try {
26
- const count = await cacheService.clearStaleCache()
27
- console.info('Successfully cleared: ', count, ' stale cache entries')
28
- } catch (err) {
29
- console.error('An error occurred while clearing stale cache:', err)
30
- }
31
- },
32
- 24 * 60 * 60 * 1000
33
- )
26
+ setInterval(
27
+ async () => {
28
+ try {
29
+ const count = await cacheService.clearStaleCache()
30
+ console.info('Successfully cleared: ', count, ' stale cache entries')
31
+ } catch (err) {
32
+ console.error('An error occurred while clearing stale cache:', err)
33
+ }
34
+ },
35
+ 24 * 60 * 60 * 1000
36
+ )
37
+ }
38
+ }
package/server/index.ts CHANGED
@@ -1,3 +1,8 @@
1
- export * from './service'
1
+ import { autoClearStale } from './controllers/cache-service'
2
2
 
3
+ export * from './service'
3
4
  export * from './controllers/cache-service'
5
+
6
+ process.on('bootstrap-module-start' as any, async ({ app, config, client }: any) => {
7
+ autoClearStale()
8
+ })