New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

basic-cache

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

basic-cache - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

4

lib/basic-cache.js

@@ -62,4 +62,8 @@ 'use strict';

exports.keys = function() {
return _.keys(cache);
};
exports.size = function() {
return _.size(cache);
};

2

package.json
{
"name": "basic-cache",
"version": "0.0.1",
"version": "0.0.2",
"main": "lib/basic-cache.js",

@@ -5,0 +5,0 @@ "description": "The most basic memory caching module ever.",

# basic-cache
[![NPM](https://nodei.co/npm/basic-cache.png?downloads=true&stars=true)](https://nodei.co/npm/basic-cache/)
The best node caching module ever.

@@ -12,8 +14,96 @@

## Documentation
_(Coming soon)_
## Methods
## Examples
_(Coming soon)_
### set(key, value, time)
Sets a `key` to a `value` and have it expire in `time` milliseconds.
```javascript
cache.set('company', 'MadGlory', 2000);
```
### get(key)
Gets the value of `key`.
```javascript
var company = cache.get('company');
```
### reset(key[, time])
Resets the expiration time of the `key`. You can optionally set a new `time`.
```javascript
cache.reset('company'); // Resets to current time + original 2000
cache.reset('company', 1000); // Resets to current time + 1000
```
### clear(key)
Removes the `key` from the cache.
```javascript
cache.clear('company');
```
### clearAll()
Removes ALL the `key`s from the cache.
```javascript
cache.clearAll();
```
### clean()
If for some reason a `key`'s `time` expired, but it still exists in the cache running this method will clear all of those `key`s.
```javascript
cache.clean();
```
### keys()
Returns all the names of the `key`s in the cache as an array.
```javascript
var keys = cache.keys();
```
### size()
Returns the number of `key`s that are currently in the cache.
```javascript
var size = cache.size();
```
## Namespacing
If you wish to namespace different cache collections there are a few ways to accomplish this.
### Key Labels
```javascript
var cache = require('basic-cache');
cache.set('NAMESPACE1:company', 'MadGlory');
cache.set('NAMESPACE2:company', 'Company 2');
```
### Cache Object
```javascript
var cache = require('basic-cache');
var multicache = {
namespace1: cache,
namespace2: cache
};
multicache.namespace1.set('company', 'MadGlory');
multicache.namespace2.set('company', 'Company 2');
```
## Contributing

@@ -20,0 +110,0 @@ In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).

@@ -88,3 +88,11 @@ 'use strict';

test.done();
},
'keys in the cache': function(test){
cache.clearAll();
cache.set('JJJ', 999, 500);
cache.set('KKK', 0, 500);
test.deepEqual(cache.keys(), ['JJJ', 'KKK'], 'Should return 2 keys.');
test.done();
}
};
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