🚀. Socket Launch Week Day 2:Introducing Manifest Alerts.Learn more
Sign In

adonis-cache

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adonis-cache - npm Package Compare versions

Comparing version
0.1.2
to
0.2.0
+1
-1
package.json
{
"name": "adonis-cache",
"version": "0.1.2",
"version": "0.2.0",
"description": "Cache provider for AdonisJs framework",

@@ -5,0 +5,0 @@ "scripts": {

@@ -145,2 +145,13 @@ # AdonisCache

Retrieving multiple items:
```javascript
values = yield Cache.many(['key1', 'key2', 'key3'])
// values = {
// key1: value,
// key2: value,
// key3: value
// }
```
#### Checking For Item Existence

@@ -172,3 +183,3 @@

```javascript
value = Cache.remember('key', minutes, function * () {
value = yield Cache.remember('key', minutes, function * () {
return yield Database.table(...).where(...).first()

@@ -205,2 +216,14 @@ })

Storing multiple items:
```javascript
const items = {
key1: 'value1',
key2: 'value2',
key3: 'value3'
}
yield Cache.putMany(items, minutes)
```
#### Store If Not Present

@@ -207,0 +230,0 @@

@@ -144,7 +144,3 @@ 'use strict'

return this.repository(
new DatabaseStore(
connection, this._app.use('Adonis/Src/Encryption'), config['table'], this._getPrefix(config)
)
)
return this.repository(new DatabaseStore(connection, config['table'], this._getPrefix(config)))
}

@@ -151,0 +147,0 @@

@@ -17,6 +17,5 @@ 'use strict'

constructor (connection, encrypter, tableName, prefix = '') {
constructor (connection, tableName, prefix = '') {
this._connection = connection
this._tableName = tableName
this._encrypter = encrypter
this._prefix = prefix

@@ -54,3 +53,3 @@ }

return Util.deserialize(this._encrypter.decrypt(cache.value))
return Util.deserialize(cache.value)
}.bind(this))

@@ -71,5 +70,5 @@ }

for (let key of keys) {
mappedValues[key] = yield this.get(key)
mappedValues[key] = this.get(key)
}
return mappedValues
return yield mappedValues
}.bind(this))

@@ -89,9 +88,9 @@ }

const prefixedKey = this._prefix + key
const encryptedValue = this._encrypter.encrypt(Util.serialize(value))
const serializedValue = Util.serialize(value)
const expiration = Math.floor((Date.now() / 1000) + minutes * 60)
try {
yield this._table().insert({key: prefixedKey, value: encryptedValue, expiration: expiration})
yield this._table().insert({key: prefixedKey, value: serializedValue, expiration: expiration})
} catch (e) {
yield this._table().where('key', prefixedKey).update({value: encryptedValue, expiration: expiration})
yield this._table().where('key', prefixedKey).update({value: serializedValue, expiration: expiration})
}

@@ -162,3 +161,3 @@ }.bind(this))

}
const currentValue = parseInt(this._encrypter.decrypt(r.value))
const currentValue = parseInt(r.value)
if (isNaN(currentValue)) {

@@ -169,3 +168,3 @@ resolve(false)

const newValue = Util.serialize(callback(currentValue))
return trx.table(this._tableName).where('key', prefixedKey).update('value', this._encrypter.encrypt(newValue))
return trx.table(this._tableName).where('key', prefixedKey).update('value', newValue)
.then(r => resolve(newValue))

@@ -223,11 +222,2 @@ })

/**
* Get the encrypter instance.
*
* @return {Adonis/Src/Encryption}
*/
getEncrypter () {
return this._encrypter
}
/**
* Get the cache key prefix.

@@ -234,0 +224,0 @@ *

@@ -53,5 +53,5 @@ 'use strict'

for (let i = 0; i < keys.length; i++) {
mappedValues[keys[i]] = yield this.get(keys[i])
mappedValues[keys[i]] = this.get(keys[i])
}
return mappedValues
return yield mappedValues
}.bind(this))

@@ -58,0 +58,0 @@ }

@@ -32,3 +32,2 @@ 'use strict'

this._events = null // The event dispatcher implementation
this._defaultCacheTime = 60 // The default number of minutes to store items

@@ -115,6 +114,2 @@ return new Proxy(this, {

return co(function * () {
if (Array.isArray(key)) {
return this.many(key)
}
let value = yield this._store.get(yield this._itemKey(key))

@@ -181,6 +176,2 @@

return co(function * () {
if (typeof key === 'object') {
return yield this.putMany(key, value)
}
if (value == null) {

@@ -374,3 +365,2 @@ return

taggedCache.setDefaultCacheTime(this._defaultCacheTime)
return taggedCache

@@ -394,21 +384,2 @@ }

/**
* Get the default cache time.
*
* @return {float|int}
*/
getDefaultCacheTime () {
return this._defaultCacheTime
}
/**
* Set the default cache time in minutes.
*
* @param {float|int} minutes
* @return {void}
*/
setDefaultCacheTime (minutes) {
this._defaultCacheTime = minutes
}
/**
* Get the cache store implementation.

@@ -423,43 +394,2 @@ *

/**
* Determine if a cached value exists.
*
* @param {string} key
* @return {Promise<boolean>}
*/
offsetExists (key) {
return this.has(key)
}
/**
* Retrieve an item from the cache by key.
*
* @param {string} key
* @return {Promise<mixed>}
*/
offsetGet (key) {
return this.get(key)
}
/**
* Store an item in the cache for the default time.
*
* @param {string} key
* @param {mixed} value
* @return {Promsie<void>}
*/
offsetSet (key, value) {
return this.put(key, value, this._defaultCacheTime)
}
/**
* Remove an item from the cache.
*
* @param {string} key
* @return {Promise<void>}
*/
offsetUnset (key) {
return this.forget(key)
}
/**
* Calculate the number of minutes with the given duration.

@@ -466,0 +396,0 @@ *