Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jjeffcaii/dcache
A simple Deno LRU cache utilities.
https://github.com/jjeffcaii/dcache
cache deno lru
Last synced: about 15 hours ago
JSON representation
A simple Deno LRU cache utilities.
- Host: GitHub
- URL: https://github.com/jjeffcaii/dcache
- Owner: jjeffcaii
- License: apache-2.0
- Created: 2021-02-19T03:38:21.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-02-20T14:48:18.000Z (over 3 years ago)
- Last Synced: 2024-10-28T12:15:56.472Z (9 days ago)
- Topics: cache, deno, lru
- Language: TypeScript
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Deno Cache - dcache :t-rex:
![GitHub Workflow Status](https://github.com/jjeffcaii/dcache/workflows/Deno/badge.svg)
![License](https://img.shields.io/github/license/jjeffcaii/dcache.svg)
[![GitHub Release](https://img.shields.io/github/release-pre/jjeffcaii/dcache.svg)](https://github.com/jjeffcaii/dcache/releases)A simple Deno LRU cache utilities.
## Example
```typescript
import { create, LRU } from "https://deno.land/x/dcache/mod.ts";// Create a LRU with cap 3.
const lru: LRU = create(3);// Set key/value
lru.set("foo", 42);
lru.set("bar", 1024, 1000); // with 1s ttl
lru.set("baz", 2048);console.log(lru.get("foo")); // print: 42
console.log(lru.get("bar")); // print: 1024
await new Promise((res) => setTimeout(res, 1000)); // sleep 1s
console.log(lru.has("bar")); // print: falselru.set("aaa", 777);
lru.set("bbb", 888);// Discards the least recently used item which is "baz"
console.log(lru.get("baz")); // print: undefinedconsole.log([...lru.keys()].join(",")); // print: bbb,aaa,foo
lru.forEach((v, k) => console.log(`${k}=${v}`));
// print:
// bbb=888
// aaa=777
// foo=42```