Add NullCacheAdapter (#2636)
* Add NullCacheAdapter * clear returns promise explicitly * Add NullCacheAdapter accessor
This commit is contained in:
committed by
Florent Vilmart
parent
33e3993a37
commit
fe62e92aa1
37
spec/NullCacheAdapter.spec.js
Normal file
37
spec/NullCacheAdapter.spec.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
var NullCacheAdapter = require('../src/Adapters/Cache/NullCacheAdapter').default;
|
||||||
|
|
||||||
|
describe('NullCacheAdapter', function() {
|
||||||
|
var KEY = 'hello';
|
||||||
|
var VALUE = 'world';
|
||||||
|
|
||||||
|
it('should expose promisifyed methods', (done) => {
|
||||||
|
var cache = new NullCacheAdapter({
|
||||||
|
ttl: NaN
|
||||||
|
});
|
||||||
|
|
||||||
|
// Verify all methods return promises.
|
||||||
|
Promise.all([
|
||||||
|
cache.put(KEY, VALUE),
|
||||||
|
cache.del(KEY),
|
||||||
|
cache.get(KEY),
|
||||||
|
cache.clear()
|
||||||
|
]).then(() => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get/set/clear', (done) => {
|
||||||
|
var cache = new NullCacheAdapter({
|
||||||
|
ttl: NaN
|
||||||
|
});
|
||||||
|
|
||||||
|
cache.put(KEY, VALUE)
|
||||||
|
.then(() => cache.get(KEY))
|
||||||
|
.then((value) => expect(value).toEqual(null))
|
||||||
|
.then(() => cache.clear())
|
||||||
|
.then(() => cache.get(KEY))
|
||||||
|
.then((value) => expect(value).toEqual(null))
|
||||||
|
.then(done);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
@@ -248,6 +248,7 @@ describe('server', () => {
|
|||||||
expect(ParseServer.GCSAdapter).toThrow('GCSAdapter is not provided by parse-server anymore; please install parse-server-gcs-adapter');
|
expect(ParseServer.GCSAdapter).toThrow('GCSAdapter is not provided by parse-server anymore; please install parse-server-gcs-adapter');
|
||||||
expect(ParseServer.FileSystemAdapter).toThrow();
|
expect(ParseServer.FileSystemAdapter).toThrow();
|
||||||
expect(ParseServer.InMemoryCacheAdapter).toThrow();
|
expect(ParseServer.InMemoryCacheAdapter).toThrow();
|
||||||
|
expect(ParseServer.NullCacheAdapter).toThrow();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
25
src/Adapters/Cache/NullCacheAdapter.js
Normal file
25
src/Adapters/Cache/NullCacheAdapter.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
export class NullCacheAdapter {
|
||||||
|
|
||||||
|
constructor(ctx) {
|
||||||
|
}
|
||||||
|
|
||||||
|
get(key) {
|
||||||
|
return new Promise((resolve, _) => {
|
||||||
|
return resolve(null);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
put(key, value, ttl) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
del(key) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
clear() {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default NullCacheAdapter;
|
||||||
@@ -2,6 +2,7 @@ import ParseServer from './ParseServer';
|
|||||||
import S3Adapter from 'parse-server-s3-adapter'
|
import S3Adapter from 'parse-server-s3-adapter'
|
||||||
import FileSystemAdapter from 'parse-server-fs-adapter'
|
import FileSystemAdapter from 'parse-server-fs-adapter'
|
||||||
import InMemoryCacheAdapter from './Adapters/Cache/InMemoryCacheAdapter'
|
import InMemoryCacheAdapter from './Adapters/Cache/InMemoryCacheAdapter'
|
||||||
|
import NullCacheAdapter from './Adapters/Cache/NullCacheAdapter'
|
||||||
import TestUtils from './TestUtils';
|
import TestUtils from './TestUtils';
|
||||||
import { useExternal } from './deprecated';
|
import { useExternal } from './deprecated';
|
||||||
import { getLogger } from './logger';
|
import { getLogger } from './logger';
|
||||||
@@ -21,4 +22,4 @@ Object.defineProperty(module.exports, 'logger', {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export default ParseServer;
|
export default ParseServer;
|
||||||
export { S3Adapter, GCSAdapter, FileSystemAdapter, InMemoryCacheAdapter, TestUtils, _ParseServer as ParseServer };
|
export { S3Adapter, GCSAdapter, FileSystemAdapter, InMemoryCacheAdapter, NullCacheAdapter, TestUtils, _ParseServer as ParseServer };
|
||||||
|
|||||||
Reference in New Issue
Block a user