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

cache-point

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

cache-point - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

29

es5/cache-point.js

@@ -16,11 +16,8 @@ 'use strict';

options = options || {};
if (!options.cacheDir) {
if (!options.dir) {
var os = require('os');
options.cacheDir = path.resolve(os.tmpdir(), 'cachePoint');
options.dir = path.resolve(os.tmpdir(), 'cachePoint');
}
this.cacheDir = options.cacheDir;
var mkdirp = require('mkdirp');
mkdirp.sync(this.cacheDir);
this.dir = options.dir;
}

@@ -31,3 +28,3 @@

value: function read(keys) {
var blobPath = path.resolve(this.cacheDir, this.getChecksum(keys));
var blobPath = path.resolve(this.dir, this.getChecksum(keys));
var promise = new Promise(function (resolve, reject) {

@@ -43,3 +40,3 @@ fs.readFile(blobPath, function (err, data) {

value: function write(keys, content) {
var blobPath = path.resolve(this.cacheDir, this.getChecksum(keys));
var blobPath = path.resolve(this.dir, this.getChecksum(keys));
return new Promise(function (resolve, reject) {

@@ -67,3 +64,3 @@ fs.writeFile(blobPath, JSON.stringify(content), function (err) {

return new Promise(function (resolve, reject) {
fs.readdir(_this.cacheDir, function (err, files) {
fs.readdir(_this.dir, function (err, files) {
if (err) {

@@ -73,3 +70,3 @@ reject(err);

var promises = files.map(function (file) {
return unlink(path.resolve(_this.cacheDir, file));
return unlink(path.resolve(_this.dir, file));
});

@@ -87,5 +84,15 @@ Promise.all(promises).then(resolve).catch(reject);

return this.clean().then(function () {
return rmdir(_this2.cacheDir);
return rmdir(_this2.dir);
});
}
}, {
key: 'dir',
get: function get() {
return this._dir;
},
set: function set(val) {
this._dir = val;
var mkdirp = require('mkdirp');
mkdirp.sync(this.dir);
}
}]);

@@ -92,0 +99,0 @@

@@ -10,3 +10,3 @@ 'use strict'

* const Cache = require('cache-point')
* const cache = new Cache({ cacheDir: '~/.cache' })
* const cache = new Cache({ dir: '~/.cache' })
*/

@@ -21,9 +21,9 @@

* @param [options] {object}
* @param [options.cacheDir] {string}
* @param [options.dir] {string}
*/
constructor (options) {
options = options || {}
if (!options.cacheDir) {
if (!options.dir) {
var os = require('os')
options.cacheDir = path.resolve(os.tmpdir(), 'cachePoint')
options.dir = path.resolve(os.tmpdir(), 'cachePoint')
}

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

*/
this.cacheDir = options.cacheDir
this.dir = options.dir
}
get dir () {
return this._dir
}
set dir (val) {
this._dir = val
const mkdirp = require('mkdirp')
mkdirp.sync(this.cacheDir)
mkdirp.sync(this.dir)
}

@@ -47,3 +53,3 @@

read (keys) {
const blobPath = path.resolve(this.cacheDir, this.getChecksum(keys))
const blobPath = path.resolve(this.dir, this.getChecksum(keys))
const promise = new Promise((resolve, reject) => {

@@ -65,3 +71,3 @@ fs.readFile(blobPath, (err, data) => {

write (keys, content) {
const blobPath = path.resolve(this.cacheDir, this.getChecksum(keys))
const blobPath = path.resolve(this.dir, this.getChecksum(keys))
return new Promise((resolve, reject) => {

@@ -93,7 +99,7 @@ fs.writeFile(blobPath, JSON.stringify(content), err => {

return new Promise((resolve, reject) => {
fs.readdir(this.cacheDir, (err, files) => {
fs.readdir(this.dir, (err, files) => {
if (err) {
reject(err)
} else {
const promises = files.map(file => unlink(path.resolve(this.cacheDir, file)))
const promises = files.map(file => unlink(path.resolve(this.dir, file)))
Promise.all(promises).then(resolve).catch(reject)

@@ -111,3 +117,3 @@ }

return this.clean().then(() => {
return rmdir(this.cacheDir)
return rmdir(this.dir)
})

@@ -114,0 +120,0 @@ }

{
"name": "cache-point",
"author": "Lloyd Brookes <75pound@gmail.com>",
"version": "0.1.4",
"version": "0.2.0",
"description": "cache-point",

@@ -6,0 +6,0 @@ "repository": "https://github.com/75lb/cache-point.git",

@@ -13,3 +13,3 @@ [![view on npm](http://img.shields.io/npm/v/cache-point.svg)](https://www.npmjs.org/package/cache-point)

const Cache = require('cache-point')
const cache = new Cache({ cacheDir: '~/.cache' })
const cache = new Cache({ dir: '~/.cache' })
```

@@ -20,3 +20,3 @@

* [new Cache([options])](#new_module_cache-point--Cache_new)
* [.cacheDir](#module_cache-point--Cache.Cache+cacheDir) : <code>string</code>
* [.dir](#module_cache-point--Cache.Cache+dir) : <code>string</code>
* [.read(keys)](#module_cache-point--Cache+read) ⇒ <code>Promise</code>

@@ -39,7 +39,7 @@ * [.write(keys, content)](#module_cache-point--Cache+write) ⇒ <code>Promise</code>

| [options] | <code>object</code> |
| [options.cacheDir] | <code>string</code> |
| [options.dir] | <code>string</code> |
<a name="module_cache-point--Cache.Cache+cacheDir"></a>
<a name="module_cache-point--Cache.Cache+dir"></a>
#### cache.cacheDir : <code>string</code>
#### cache.dir : <code>string</code>
Cache directory

@@ -46,0 +46,0 @@

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