@@ -1,26 +1,24 @@
|
||||
const InMemoryCache = require('../lib/Adapters/Cache/InMemoryCache').default;
|
||||
|
||||
|
||||
describe('InMemoryCache', function() {
|
||||
const BASE_TTL = {
|
||||
ttl: 100
|
||||
ttl: 100,
|
||||
};
|
||||
const NO_EXPIRE_TTL = {
|
||||
ttl: NaN
|
||||
ttl: NaN,
|
||||
};
|
||||
const KEY = 'hello';
|
||||
const KEY_2 = KEY + '_2';
|
||||
|
||||
const VALUE = 'world';
|
||||
|
||||
|
||||
function wait(sleep) {
|
||||
return new Promise(function(resolve) {
|
||||
setTimeout(resolve, sleep);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
it('should destroy a expire items in the cache', (done) => {
|
||||
it('should destroy a expire items in the cache', done => {
|
||||
const cache = new InMemoryCache(BASE_TTL);
|
||||
|
||||
cache.put(KEY, VALUE);
|
||||
@@ -29,13 +27,13 @@ describe('InMemoryCache', function() {
|
||||
expect(value).toEqual(VALUE);
|
||||
|
||||
wait(BASE_TTL.ttl * 10).then(() => {
|
||||
value = cache.get(KEY)
|
||||
value = cache.get(KEY);
|
||||
expect(value).toEqual(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should delete items', (done) => {
|
||||
it('should delete items', done => {
|
||||
const cache = new InMemoryCache(NO_EXPIRE_TTL);
|
||||
cache.put(KEY, VALUE);
|
||||
cache.put(KEY_2, VALUE);
|
||||
@@ -52,7 +50,7 @@ describe('InMemoryCache', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
it('should clear all items', (done) => {
|
||||
it('should clear all items', done => {
|
||||
const cache = new InMemoryCache(NO_EXPIRE_TTL);
|
||||
cache.put(KEY, VALUE);
|
||||
cache.put(KEY_2, VALUE);
|
||||
@@ -70,5 +68,4 @@ describe('InMemoryCache', function() {
|
||||
const cache = new InMemoryCache({});
|
||||
expect(cache.ttl).toEqual(5 * 1000);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user