Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ssr-cache

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ssr-cache - npm Package Compare versions

Comparing version 0.9.2 to 0.9.5

44

index.js
'use strict';
const memcached = require('memjs')
const memcached = require('memcached')
const LRU = require('lru-cache');
const memcached_api = process.env.MEMCACHIER_SERVERS || 'localhost:11211'

@@ -11,6 +12,6 @@ /**

*/
function Cache({type = 'memcached', prefix = 'client'}) {
function Cache({type = 'memcached', prefix = 'client', expiration = 600}) {
this.type = type;
this.prefix = prefix;
this.cache = this[type]();
this.cache = this[type](expiration);
}

@@ -37,5 +38,26 @@

/**
*
* @param key
* @returns {Promise}
*/
Cache.prototype.delete = function({key}) {
return new Promise((resolve, reject) =>{
if(!key) reject('key {string} is not defined');
// if type lru usually return value
if(this.type === 'lru' ) {
let value = this.cache.del(this.prefix+key);
return value ? resolve(value) : reject(value);
}
this.cache.del(this.prefix+key, function (err, val) {
if(err) console.log(err)
err || !val ? reject(err ? 'memcached is not runing!' : val) : resolve(val)
})
})
};
/**
*
* @param key
* @param value

@@ -52,3 +74,3 @@ * @param expires

// memcached return callback value
this.cache.set(this.prefix+key, value, {expires}, function (err, val) {
this.cache.set(this.prefix+key, value, expires, function (err, val) {
if(err) console.log(err)

@@ -64,6 +86,6 @@ err ? resolve(value) : resolve(val)

*/
Cache.prototype.lru = () => {
Cache.prototype.lru = ({expiration}) => {
return LRU({
max: 1000,
maxAge: 1000 * 60 * 10 // 10 min cache
maxAge: 1000 * expiration // 10 min cache
})

@@ -74,6 +96,12 @@ };

*/
Cache.prototype.memcached = () => {
return memcached.Client.create();
Cache.prototype.memcached = ({expiration}) => {
// return memcached.Client.create();
try {
return new Memcached(memcached_api, {retries:10,retry:10000,remove:true, maxExpiration: expiration });
} catch (e){
console.log(e)
return e
}
};
module.exports = Cache;

4

package.json
{
"name": "ssr-cache",
"version": "0.9.2",
"version": "0.9.5",
"description": "Api Serve-Side Cache Wrapper for Lru and Memcached",

@@ -13,4 +13,4 @@ "main": "index.js",

"lru-cache": "^4.1.1",
"memjs": "^1.0.0"
"memcached": "^2.2.2"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc