BVB Source Codes

parse-server Show CacheController.js Source code

Return Download parse-server: download CacheController.js Source code - Download parse-server Source code - Type:.js
  1. import AdaptableController from './AdaptableController';
  2. import CacheAdapter        from '../Adapters/Cache/CacheAdapter';
  3.  
  4. const KEY_SEPARATOR_CHAR = ':';
  5.  
  6. function joinKeys(...keys) {
  7.   return keys.join(KEY_SEPARATOR_CHAR);
  8. }
  9.  
  10. /**
  11.  * Prefix all calls to the cache via a prefix string, useful when grouping Cache by object type.
  12.  *
  13.  * eg "Role" or "Session"
  14.  */
  15. export class SubCache {
  16.   constructor(prefix, cacheController, ttl) {
  17.     this.prefix = prefix;
  18.     this.cache = cacheController;
  19.     this.ttl = ttl;
  20.   }
  21.  
  22.   get(key) {
  23.     const cacheKey = joinKeys(this.prefix, key);
  24.     return this.cache.get(cacheKey);
  25.   }
  26.  
  27.   put(key, value, ttl) {
  28.     const cacheKey = joinKeys(this.prefix, key);
  29.     return this.cache.put(cacheKey, value, ttl);
  30.   }
  31.  
  32.   del(key) {
  33.     const cacheKey = joinKeys(this.prefix, key);
  34.     return this.cache.del(cacheKey);
  35.   }
  36.  
  37.   clear() {
  38.     return this.cache.clear();
  39.   }
  40. }
  41.  
  42.  
  43. export class CacheController extends AdaptableController {
  44.  
  45.   constructor(adapter, appId, options = {}) {
  46.     super(adapter, appId, options);
  47.  
  48.     this.role = new SubCache('role', this);
  49.     this.user = new SubCache('user', this);
  50.   }
  51.  
  52.   get(key) {
  53.     const cacheKey = joinKeys(this.appId, key);
  54.     return this.adapter.get(cacheKey).then(null, () => Promise.resolve(null));
  55.   }
  56.  
  57.   put(key, value, ttl) {
  58.     const cacheKey = joinKeys(this.appId, key);
  59.     return this.adapter.put(cacheKey, value, ttl);
  60.   }
  61.  
  62.   del(key) {
  63.     const cacheKey = joinKeys(this.appId, key);
  64.     return this.adapter.del(cacheKey);
  65.   }
  66.  
  67.   clear() {
  68.     return this.adapter.clear();
  69.   }
  70.  
  71.   expectedAdapterType() {
  72.     return CacheAdapter;
  73.   }
  74. }
  75.  
  76. export default CacheController;
  77.  
downloadCacheController.js Source code - Download parse-server Source code
Related Source Codes/Software:
react-boilerplate - 2017-06-07
webtorrent - Streaming torrent client for the web ... 2017-06-06
machine-learning-for-software-engineers - A complete daily plan for studying to become a mac... 2017-06-06
upterm - A terminal emulator for the 21st century. 2017-06-06
lottie-android - Render After Effects animations natively on Androi... 2017-06-07
AsyncDisplayKit - Smooth asynchronous user interfaces for iOS apps. ... 2017-06-07
ionicons - The premium icon font for Ionic ... 2017-06-07
storybook - 2017-06-07
prettier - Prettier is an opinionated JavaScript formatter. ... 2017-06-08
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top