Skip to content
Snippets Groups Projects
Commit 8d1dbf51 authored by richard.petersen's avatar richard.petersen :sailboat:
Browse files

Clear the cache on version update

parent c9d89ba0
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ import fetch from 'node-fetch'
import { config } from './config.js'
import { getRedisKey, hash } from './util.js'
import { logger } from './logger.js'
import * as cache from './cache.js'
import * as redis from './redis.js'
let latestVersion
......@@ -49,15 +50,16 @@ export async function getLatestVersion () {
}
export function registerLatestVersionListener (client) {
if (redis.isEnabled()) {
const key = getRedisKey({ name: 'updateLatestVersion' })
client.subscribe(key, (errs, count) => logger.info(`[Redis] Subscribed to ${key}.`))
client.on('message', async (channel, message) => {
if (channel !== key) return
await config.load()
latestVersion = message
})
}
if (!redis.isEnabled()) return
const key = getRedisKey({ name: 'updateLatestVersion' })
client.subscribe(key, (errs, count) => logger.info(`[Redis] Subscribed to ${key}.`))
client.on('message', async (channel, message) => {
if (channel !== key) return
await config.load()
cache.clear()
latestVersion = message
})
}
export async function updateVersionProcessor () {
......@@ -70,6 +72,9 @@ export async function updateVersionProcessor () {
if (redis.isEnabled()) {
redis.pubClient.publish(getRedisKey({ name: 'updateLatestVersion' }), fetchedVersion)
await redis.client.set(getRedisKey({ name: 'latestVersion' }), fetchedVersion)
} else {
// if redis is disabled, this will only be trigger by a setInterval and not from a redis event
cache.clear()
}
return (latestVersion = fetchedVersion)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment