mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 00:11:49 +03:00
5ab81554fc
refs https://github.com/TryGhost/Arch/issues/5 - Current event-aware cache wrapper has been using a timestamp as a way to create keys in Redis cache and reset them all at once. We are now moving on to the updated Redis adapter that supports "reset()" natively, so there's no need for synthetic resets.
49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
const assert = require('assert/strict');
|
|
const InMemoryCache = require('@tryghost/adapter-cache-memory-ttl');
|
|
|
|
const EventAwareCacheWrapper = require('../index');
|
|
const {EventEmitter} = require('stream');
|
|
|
|
describe('EventAwareCacheWrapper', function () {
|
|
it('Can initialize', function () {
|
|
const cache = new InMemoryCache();
|
|
const wrappedCache = new EventAwareCacheWrapper({
|
|
cache
|
|
});
|
|
assert.ok(wrappedCache);
|
|
});
|
|
|
|
describe('get', function () {
|
|
it('calls a wrapped cache with extra key', async function () {
|
|
const cache = new InMemoryCache();
|
|
const wrapper = new EventAwareCacheWrapper({
|
|
cache: cache
|
|
});
|
|
|
|
await wrapper.set('a', 'b');
|
|
assert.equal(await wrapper.get('a'), 'b');
|
|
assert.equal(await cache.get('a'), 'b');
|
|
});
|
|
});
|
|
|
|
describe('listens to reset events', function () {
|
|
it('resets the cache when reset event is triggered', async function () {
|
|
const cache = new InMemoryCache();
|
|
|
|
const eventRegistry = new EventEmitter();
|
|
const wrapper = new EventAwareCacheWrapper({
|
|
cache: cache,
|
|
resetEvents: ['site.changed'],
|
|
eventRegistry: eventRegistry
|
|
});
|
|
|
|
await wrapper.set('a', 'b');
|
|
assert.equal(await wrapper.get('a'), 'b');
|
|
|
|
eventRegistry.emit('site.changed');
|
|
|
|
assert.equal(await wrapper.get('a'), undefined);
|
|
});
|
|
});
|
|
});
|