Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/will123195/disk-cache
Simple disk caching
https://github.com/will123195/disk-cache
Last synced: 10 days ago
JSON representation
Simple disk caching
- Host: GitHub
- URL: https://github.com/will123195/disk-cache
- Owner: will123195
- Created: 2015-01-08T22:35:37.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-09T00:06:28.000Z (almost 10 years ago)
- Last Synced: 2024-10-06T08:41:51.451Z (3 months ago)
- Language: JavaScript
- Size: 129 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# disk-cache
[![Build Status](https://travis-ci.org/will123195/disk-cache.svg)](https://travis-ci.org/will123195/disk-cache)
Simple disk caching - cache strings to files on disk
## Installation
```
npm install disk-cache
```## Methods
### cache.get(key, [ttl], cb)
### cache.set(key, value, cb)## Usage
```js
var cache = require('disk-cache')({
path: './cache/' + Math.random()
})var key = 'some/file.txt'
var value = 'abc123'
cache.set(key, value, function(err) {var ttl = 60 * 60 // 1 hour
cache.get(key, ttl, function(err, val) {if (err.notFound) {
// this value is not cached or has expired
return
}console.log(val) // abc123
})
})
```