https://github.com/bradmkjr/sqlcachedb
Using SQLite database for a persistant object cache.
https://github.com/bradmkjr/sqlcachedb
caching nodejs persistant sqlite3 storage
Last synced: 3 months ago
JSON representation
Using SQLite database for a persistant object cache.
- Host: GitHub
- URL: https://github.com/bradmkjr/sqlcachedb
- Owner: bradmkjr
- Created: 2017-10-22T19:07:28.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-29T14:03:20.000Z (over 6 years ago)
- Last Synced: 2025-02-24T09:05:37.972Z (3 months ago)
- Topics: caching, nodejs, persistant, sqlite3, storage
- Language: JavaScript
- Homepage: https://github.com/bradmkjr/sqlcachedb
- Size: 20.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sqlcachedb
Using SQLite database for a persistant object cache. This packaged is designed to easily store large amounts of data directly into a SQLite3 database for retrival at a later date. It's not as fast as using memory based storage or file based storage.
# Installation
npm install sqlcachedb --save
# Usage
Current default cache lifetime is 6 hours, future versions will allow this to be modified.
## Basic Example
```javascript
var cache = require('sqlcachedb');cache.setCache('url','https://github.com', function(){
cache.getCache('url', function(err,data){
console.log(data);
});});
```## setCache
Store a value into cache based on a key
```javascript
var cache = require('sqlcachedb');cache.setCache('test', Math.random(), function(){});
cache.setCache('test2', Math.random(), function(){});
cache.setCache('test3', Math.random(), function(){});
```## getCache
Retrieve a value from cache based on a key
```javascript
var cache = require('sqlcachedb');cache.setCache('url','https://github.com', function(){
cache.getCache('url', function(err,data){
console.log(data);
});});
```## getKeys
Gets all the keys from cache
```javascript
var cache = require('sqlcachedb');cache.setCache('test', Math.random(), function(){});
cache.setCache('test2', Math.random(), function(){});
cache.setCache('test3', Math.random(), function(){});
cache.getKeys(function(err, keys){
console.log(keys);
})
```## getActiveKeys
Gets all the keys from cache updated within cache lifetime
```javascript
var cache = require('sqlcachedb');cache.setCache('test', Math.random(), function(){});
cache.setCache('test2', Math.random(), function(){});
cache.setCache('test3', Math.random(), function(){});
cache.getActiveKeys(function(err, keys){
console.log(keys);
});
```## purgeKey
Remove data from cache based on key
```javascript
var cache = require('sqlcachedb');cache.setCache('test4', 'Houdini', function(){
cache.getCache('test4',function(err, data){
console.log('test4: '+data);
cache.purgeKey('test4', function(err){cache.getCache('test4',function(err, data){
console.log('test4: '+data);
});
});
});
});
```## purgeCache
```javascript
Remove all data from cache
var cache = require('sqlcachedb');cache.purgeCache(function(){
cache.getKeys(function(err, keys){
console.log(keys);
});
});
```## cleanCache
Remove all data from cache which has expired
```javascript
var cache = require('sqlcachedb');cache.cleanCache(function(){
cache.getKeys(function(err, keys){
console.log(keys);
});
});
```**Note:** This package is in Alpha stages, probably should not have been published to the repository in it's current state.
caveat emptor
[](https://nodei.co/npm/sqlcachedb/)