Skip to content

Commit

Permalink
Another try for #3447
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed May 29, 2017
1 parent 183f113 commit 7f15394
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,7 @@ exports = module.exports = internals.Plugin = function (server, connections, env
test: (name, request, next) => request.connection.auth.test(name, request, next)
};

this.cache = internals.cache;
this.cache.provision = (opts, callback) => {

if (!callback) {
return Promises.wrap(null, this.cache.provision, [opts]);
}

return this.root._createCache(opts, callback);
};

this.cache = internals.cache(this);
this._single();

// Decorations
Expand Down Expand Up @@ -334,20 +325,34 @@ internals.Plugin.prototype.bind = function (context) {
};


internals.cache = function (options, _segment) {
internals.cache = (plugin) => {

const policy = function (options, _segment) {

options = Schema.apply('cachePolicy', options);

options = Schema.apply('cachePolicy', options);
const segment = options.segment || _segment || (plugin.realm.plugin ? '!' + plugin.realm.plugin : '');
Hoek.assert(segment, 'Missing cache segment name');

const segment = options.segment || _segment || (this.realm.plugin ? '!' + this.realm.plugin : '');
Hoek.assert(segment, 'Missing cache segment name');
const cacheName = options.cache || '_default';
const cache = plugin.root._caches[cacheName];
Hoek.assert(cache, 'Unknown cache', cacheName);
Hoek.assert(!cache.segments[segment] || cache.shared || options.shared, 'Cannot provision the same cache segment more than once');
cache.segments[segment] = true;

const cacheName = options.cache || '_default';
const cache = this.root._caches[cacheName];
Hoek.assert(cache, 'Unknown cache', cacheName);
Hoek.assert(!cache.segments[segment] || cache.shared || options.shared, 'Cannot provision the same cache segment more than once');
cache.segments[segment] = true;
return new Catbox.Policy(options, cache.client, segment);
};

policy.provision = (opts, callback) => {

if (!callback) {
return Promises.wrap(null, plugin.cache.provision, [opts]);
}

return plugin.root._createCache(opts, callback);
};

return new Catbox.Policy(options, cache.client, segment);
return policy;
};


Expand Down

0 comments on commit 7f15394

Please sign in to comment.