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

sync-disk-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

sync-disk-cache - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

84

index.js

@@ -11,5 +11,6 @@ 'use strict';

var chmod = fs.chmodSync;
var tmpDir = require('os').tmpDir();
var tmpDir = require('os').tmpdir();
var debug = require('debug')('sync-disk-cache');
var zlib = require('zlib');
var heimdall = require('heimdalljs');

@@ -21,4 +22,37 @@ var mode = {

var CacheEntry = require('./lib/cache-entry');
var Metric = require('./lib/metric');
if (!heimdall.hasMonitor('sync-disk-cache')) {
heimdall.registerMonitor('sync-disk-cache', function SyncDiskCacheSchema() {});
}
/*
* @private
*
* Defines a function on the given object at the given property name. Wraps
* the function with metric recording for heimdalljs.
*
* @method defineFunction
* @param Object obj the object on which to define the function
* @param String name the name to use for the function
* @param Function fn
* @returns Void
*/
function defineFunction(obj, name, fn) {
obj[name] = function() {
var stats = heimdall.statsFor('sync-disk-cache');
var metrics = stats[name] = stats[name] || new Metric();
metrics.start();
var result = fn.apply(this, arguments);
metrics.stop();
return result;
};
}
/*
* @private
* @method processFile

@@ -95,3 +129,3 @@ * @param String filePath the path of the cached file

this.key = key || 'default-disk-cache';
this.root = path.join(this.tmpDir, this.key);
this.root = path.join(this.tmpDir, 'if-you-need-to-delete-this-open-an-issue-sync-disk-cache', this.key);

@@ -105,6 +139,4 @@ debug('new Cache { root: %s, compression: %s }', this.root, this.compression);

* @method clear
* @returns {Promise} - fulfills when the cache has been cleared
* - rejects when a failured occured during cache clear
*/
Cache.prototype.clear = function() {
defineFunction(Cache.prototype, 'clear', function() {
debug('clear: %s', this.root);

@@ -115,3 +147,3 @@

);
};
});

@@ -123,6 +155,5 @@ /*

* @param {String} key the key to check existence of
* @return {Promise} - fulfills with either true | false depending if the key was found or not
* - rejects when a failured occured when checking existence of the key
* @return {Boolean} - whether the key was found or not
*/
Cache.prototype.has = function(key) {
defineFunction(Cache.prototype, 'has', function(key) {
var filePath = this.pathFor(key);

@@ -132,3 +163,3 @@ debug('has: %s', filePath);

return fs.existsSync(filePath);
};
});

@@ -140,6 +171,5 @@ /*

* @param {String} key they key to retrieve
* @return {Promise} - fulfills with either the cache entry, or a cache miss entry
* - rejects when a failure occured looking retrieving the key
* @return {CacheEntry} - either the cache entry, or a cache miss entry
*/
Cache.prototype.get = function(key) {
defineFunction(Cache.prototype, 'get', function(key) {
var filePath = this.pathFor(key);

@@ -153,3 +183,3 @@ debug('get: %s', filePath);

}
};
});

@@ -162,6 +192,5 @@ /*

* @param {String} value the value we wish the key to be stored with
* @returns {Promise#fulfilled} if the value was coõstored as the key
* @returns {Promise#rejected} when a failure occured persisting the key
* @returns {String} filePath of the stored value
*/
Cache.prototype.set = function(key, value) {
defineFunction(Cache.prototype, 'set', function(key, value) {
var filePath = this.pathFor(key);

@@ -175,3 +204,3 @@ debug('set : %s', filePath);

return filePath;
};
});

@@ -183,6 +212,5 @@ /*

* @param {String} key the key to remove from the cache
* @returns {Promise#fulfilled} if the removal was successful
* @returns {Promise#rejection} if something went wrong while removing the key
* @returns {Boolean} - whether the key was removed
*/
Cache.prototype.remove = function(key) {
defineFunction(Cache.prototype, 'remove', function(key) {
var filePath = this.pathFor(key);

@@ -196,3 +224,3 @@ debug('remove : %s', filePath);

}
};
});

@@ -206,5 +234,5 @@ /*

*/
Cache.prototype.pathFor = function(key) {
defineFunction(Cache.prototype, 'pathFor', function(key) {
return path.join(this.root, key);
};
});

@@ -218,6 +246,6 @@ /*

*/
Cache.prototype.decompress = function(value) {
defineFunction(Cache.prototype, 'decompress', function(value) {
if (!this.compression) { return value; }
return COMPRESSIONS[this.compression].out(value);
};
});

@@ -231,7 +259,7 @@ /*

*/
Cache.prototype.compress = function(value) {
defineFunction(Cache.prototype, 'compress', function(value) {
if (!this.compression) { return value; }
return COMPRESSIONS[this.compression].in(value);
};
});
module.exports = Cache;
{
"name": "sync-disk-cache",
"version": "1.0.1",
"version": "1.1.0",
"description": "sync disk cache",

@@ -30,2 +30,3 @@ "files": [

"debug": "^2.1.3",
"heimdalljs": "^0.2.3",
"mkdirp": "^0.5.0",

@@ -32,0 +33,0 @@ "rimraf": "^2.2.8"

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