https://github.com/lambdalisue/deno-ttl-cache
🦕 Simple TTL cache library for TypeScript
https://github.com/lambdalisue/deno-ttl-cache
cache deno jsr ttl
Last synced: 27 days ago
JSON representation
🦕 Simple TTL cache library for TypeScript
- Host: GitHub
- URL: https://github.com/lambdalisue/deno-ttl-cache
- Owner: lambdalisue
- License: mit
- Created: 2023-06-27T12:37:26.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-06T09:44:08.000Z (about 1 year ago)
- Last Synced: 2025-03-07T13:40:50.449Z (about 2 months ago)
- Topics: cache, deno, jsr, ttl
- Language: TypeScript
- Homepage: https://jsr.io/@lambdalisue/ttl-cache
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ttl-cache
[](https://jsr.io/@lambdalisue/ttl-cache)
[](https://github.com/lambdalisue/deno-ttl-cache/releases)
[](https://doc.deno.land/https/deno.land/x/ttl_cache/mod.ts)
[](https://github.com/lambdalisue/deno-ttl-cache/actions?query=workflow%3ATest)Simple TTL cache library for [deno].
[deno]: https://deno.land/
## Usage
```ts
import { Cache } from "https://deno.land/x/ttl_cache@$MODULE_VERSION/mod.ts";// Create a cache instance that has 1000 ms TTL (default)
const cache = new Cache(1000);// Set
// key1 will be removed after 1000 ms
// key2 will be removed after 5000 ms
cache
.set("key1", "value")
.set("key2", "value", { ttl: 5000 });// Size
cache.size(); // => 2// Get
cache.get("key1"); // => "value"// Has
cache.has("key1"); // => true// Delete
cache.delete("key1"); // => true// Clear
cache.clear();
```## License
The code follows MIT license written in [LICENSE](./LICENSE). Contributors need
to agree that any modifications sent in this repository follow the license.