Skip to content

Commit 7a34dd8

Browse files
committed
Merge branch 'release/0.0.2'
2 parents 89bb818 + 30d8ff2 commit 7a34dd8

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

index.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,31 @@ module.exports = function defineSailsCacheHook(sails) {
44
return {
55
defaults: {
66
stash: {
7-
store: process.env.CACHE_STORE || 'redis',
8-
stores: {
9-
redis: {
10-
store: 'redis',
11-
datastore: 'cache',
12-
},
13-
memcached: {
14-
store: 'memcached',
15-
datastore: 'cache',
16-
},
7+
cachestore: 'default',
8+
},
9+
cachestores: {
10+
default: {
11+
store: 'redis',
12+
datastore: 'cache',
1713
},
1814
},
1915
},
2016
initialize: async function () {
21-
function getCacheStore(store) {
22-
switch (sails.config.stash.stores[store].store) {
17+
function getCacheStore(cachestore) {
18+
if (!sails.config.cachestores[cachestore]) {
19+
throw new Error('The provided cachestore coult not be found.')
20+
}
21+
switch (sails.config.cachestores[cachestore].store) {
2322
case 'redis':
2423
return new RedisStore(sails)
2524
default:
26-
throw new Error('Invalid cache store provided')
25+
throw new Error(
26+
'Invalid store provided, supported stores are redis or memcached.',
27+
)
2728
}
2829
}
2930

30-
let cacheStore = getCacheStore(
31-
sails.config.stash.stores[sails.config.stash.store].store,
32-
)
31+
let cacheStore = getCacheStore(sails.config.stash.cachestore)
3332

3433
sails.cache = {
3534
get: cacheStore.get.bind(cacheStore),
@@ -41,8 +40,8 @@ module.exports = function defineSailsCacheHook(sails) {
4140
pull: cacheStore.pull.bind(cacheStore),
4241
forever: cacheStore.forever.bind(cacheStore),
4342
destroy: cacheStore.destroy.bind(cacheStore),
44-
store: function (store) {
45-
return getCacheStore(store)
43+
store: function (cachestore) {
44+
return getCacheStore(cachestore)
4645
},
4746
}
4847
},

lib/stores/cache-store.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ function CacheStore(sails) {
66
}
77

88
this.sails = sails
9-
this.datastore = sails.config.stash.stores[sails.config.stash.store].datastore
9+
this.datastore =
10+
sails.config.cachestores[sails.config.stash.cachestore].datastore
1011
this.store = null
1112
}
1213
/**

lib/stores/redis-store.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ function RedisStore(sails) {
77

88
RedisStore.prototype = Object.create(CacheStore.prototype)
99
RedisStore.prototype.constructor = RedisStore
10-
RedisStore.prototype.getStore = CacheStore.prototype.getStore
1110

1211
/**
1312
* Retrieves the value associated with the specified key from the cache store.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sails-stash",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "Efficient and intuitive caching for your Sails applications.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)