https://github.com/patrixr/tronicache
An opinionated memcache
https://github.com/patrixr/tronicache
cache concept design-pattern functional hacktoberfest javascript memcache
Last synced: 6 months ago
JSON representation
An opinionated memcache
- Host: GitHub
- URL: https://github.com/patrixr/tronicache
- Owner: patrixr
- License: mit
- Created: 2019-10-24T02:18:01.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T08:26:16.000Z (about 3 years ago)
- Last Synced: 2025-04-19T10:56:53.288Z (about 1 year ago)
- Topics: cache, concept, design-pattern, functional, hacktoberfest, javascript, memcache
- Language: JavaScript
- Homepage:
- Size: 40 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tronicache
[](https://forthebadge.com)
An argument-aware opinionated memcache
# Installation
```bash
npm install --save tronicache
```
# Usage
## Create a cached service
### Indefinite caching by default
```javascript
const { cached } = require('tronicache');
const service = cached({
getUser(uid) {
// cached indefinitely
}
})
```
### Configurable timeout
```javascript
const { cached } = require('tronicache');
const service = cached({
timeout: 2 * 60 * 6000, // all methods at the root are cached for 2 minutes
getUser(uid) {
// cached for 2 minutes
}
})
```
### Nested namespace support
```javascript
const { cached } = require('tronicache');
const service = cached({
users: {
getUser(uid) {
// cached indefinitely
},
posts: {
// all methods within 'posts' will be cached for 2 minutes
timeout: 2 * 60 * 1000,
postsOfUser(uid) {
const user = this.users.getUser(uid); // notice the scope
// ...
}
}
},
notifications: {
// nothing under 'notifications' is cached
cache: false,
fetch() {
// ...
},
archive: {
cache: true, // override in the subnamespace
fetch() { }
}
}
});
```