Skip to content

Commit 9ddb875

Browse files
committed
Update readme
1 parent c75d0dd commit 9ddb875

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

Diff for: README.md

+41-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
1-
# deno-caching
1+
# Caching
2+
3+
## `Cache`
4+
5+
```ts
6+
const cache = new Cache<string>();
7+
8+
const cacheKey = 'abc123';
9+
10+
/**
11+
* Load from cache.
12+
* If not found, value will be generated and stored in cache.
13+
*/
14+
cache.load(cacheKey, () => {
15+
const result = 'Lorem ipsum';
16+
17+
// Some expensive operation
18+
// ...
19+
20+
return result
21+
}); // -> string
22+
23+
24+
/**
25+
* Load from cache.
26+
*/
27+
cache.load(cacheKey); // -> string | undefined
28+
29+
30+
/**
31+
* Save to cache.
32+
*/
33+
cache.save(cacheKey, 'Lorem ipsum');
34+
35+
36+
/**
37+
* Check if cache exists.
38+
*/
39+
cache.has(cacheKey); // -> boolean
40+
41+
```

0 commit comments

Comments
 (0)