Skip to content

Commit 0d9b80e

Browse files
committed
docs: wip docs
1 parent 349a920 commit 0d9b80e

5 files changed

Lines changed: 270 additions & 215 deletions

File tree

docs/content/docs/db.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
"contentPath": "./quick_setup.md",
1212
"category": "Guides"
1313
},
14+
{
15+
"permalink": "usage",
16+
"title": "Usage",
17+
"contentPath": "./usage.md",
18+
"category": "Guides"
19+
},
1420
{
1521
"permalink": "drivers",
1622
"title": "Drivers",
1723
"contentPath": "./drivers.md",
1824
"category": "Guides"
1925
},
20-
{
21-
"permalink": "events",
22-
"title": "Events",
23-
"contentPath": "./digging_deeper/events.md",
24-
"category": "Digging Deeper"
25-
},
2626
{
2727
"permalink": "logging",
2828
"title": "Logging",

docs/content/docs/digging_deeper/events.md

Lines changed: 0 additions & 137 deletions
This file was deleted.

docs/content/docs/digging_deeper/logging.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
summary: Bentocache logs a lot of information throughout its execution. Learn how to plug in your own logger.
2+
summary: Learn to plug in your own logger to Verrou
33
---
44

55
# Logging
66

7-
In case you encounter any issues, or if you just want more visibility and information about what Bentocache is doing in production, you can plug in a custom logger when you create an instance of Bentocache.
7+
In case you encounter any issues, or if you just want more visibility and information about what Verrou is doing, you can plug in a custom logger when you create an instance of Verrou.
88

99
Your logger must comply with the following interface:
1010

@@ -34,7 +34,7 @@ export interface Logger {
3434

3535
A compatible logger is, for example, [Pino](https://github.com/pinojs/pino), which is the de-facto logger to use for modern Node.js projects.
3636

37-
Next, when you create your Bentocache instance, you can inject your logger. Example with Pino:
37+
Next, when you create your Verrou instance, you can inject your logger. Example with Pino:
3838

3939
```ts
4040
import { pino } from 'pino'
@@ -44,14 +44,24 @@ const logger = pino({
4444
transport: { target: 'pino-pretty' }
4545
})
4646

47-
const bento = new BentoCache({
47+
const verrou = new Verrou({
4848
// ...
4949
logger,
5050
})
5151
```
5252

53-
Bentocache will create a child logger with the label `pkg: "bentocache"`, allowing you to filter easily on your end.
53+
Verrou will create a child logger with the label `pkg: "verrou"`, allowing you to filter easily on your end.
5454

55-
Sometimes other child loggers are created depending on the context. Also logs of various levels are generated throughout the execution: trace, error, info, etc...
55+
If using the `LockFactory` API, you can also do the same :
5656

57-
You will discover this quite easily when trying it out.
57+
```ts
58+
import { pino } from 'pino'
59+
import { LockFactory } from '@verrou/core'
60+
61+
const logger = pino({
62+
level: 'trace',
63+
transport: { target: 'pino-pretty' }
64+
})
65+
66+
const lockFactory = new LockFactory(memoryStore(), { logger })
67+
```

docs/content/docs/extend/custom_lock_store.md

Lines changed: 34 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,84 @@
11
---
2-
summary: Learn how to create a custom cache driver for BentoCache
2+
summary: Learn how to create a custom lock driver for Verrou
33
---
44

5-
# Create a custom cache driver
5+
# Create a custom lock driver
66

7-
Extending BentoCache with your own cache driver is easy. What you need is a class that implements the `L1CacheDriver` or `L2CacheDriver` interfaces accessible from `bentocache/types`. The interface is defined as follows:
7+
Extending Verrou with your own cache driver is easy. What you need is a class that implements the `LockStore` interface accessible from `verrou/types`. The interface is defined as follows:
88

99
```ts
10-
interface L2CacheDriver {
10+
interface LockStore {
1111
/**
12-
* Returns a new instance of the driver namespace
12+
* Save the lock in the store if not already locked
1313
*/
14-
namespace(namespace: string): CacheDriver
14+
save(key: string, owner: string, ttl: number | null | undefined): Promise<boolean>
1515

1616
/**
17-
* Get a value from the cache
17+
* Delete the lock from the store
1818
*/
19-
get(key: string): Promise<string | undefined>
19+
delete(key: string, owner: string): Promise<void>
2020

2121
/**
22-
* Get the value of a key and delete it
23-
*
24-
* Returns the value if the key exists, undefined otherwise
22+
* Check if the lock exists
2523
*/
26-
pull(key: string): Promise<string | undefined>
24+
exists(key: string): Promise<boolean>
2725

2826
/**
29-
* Put a value in the cache.
30-
* If `ttl` is not defined, the value will be stored forever
31-
* Returns true if the value was set, false otherwise
27+
* Extend the lock expiration
3228
*/
33-
set(key: string, value: string, ttl?: number): Promise<boolean>
29+
extend(key: string, duration: Duration): Promise<void>
3430

3531
/**
36-
* Check if a key exists in the cache
37-
*/
38-
has(key: string): Promise<boolean>
39-
40-
/**
41-
* Remove all items from the cache
42-
*/
43-
clear(): Promise<void>
44-
45-
/**
46-
* Delete a key from the cache
47-
* Returns true if the key was deleted, false otherwise
48-
*/
49-
delete(key: string): Promise<boolean>
50-
51-
/**
52-
* Delete multiple keys from the cache
53-
*/
54-
deleteMany(keys: string[]): Promise<boolean>
55-
56-
/**
57-
* Closes the connection to the cache.
58-
* Some drivers may not need this
32+
* Disconnect the store
5933
*/
6034
disconnect(): Promise<void>
6135
}
6236
```
6337

64-
Similarly, the `L1CacheDriver` interface is the same, except that it is not async.
65-
66-
So this should be quite easy to implement. Feel free to take a lot at [the existings drivers](https://github.com/Julien-R44/bentocache/tree/develop/drivers) implementations for inspiration.
38+
Feel free to take a lot at [the existing drivers](https://github.com/Julien-R44/verrou/tree/develop/src/drivers) implementations for inspiration.
6739

68-
Also note that your driver will receive two additional parameters in the constructor : `ttl` and `prefix`. These parameters are common to every drivers and their purpose is explained in the [options](../options.md) page.
69-
70-
Once you defined you driver, you can create a factory function that will be used by Bentocache to create instances of your driver at runtime. The factory function must be something like this:
40+
Once you defined you driver, you can create a factory function that will be used by Verrou to create instances of your driver at runtime. The factory function must be something like this:
7141

7242
```ts
73-
import type { CreateDriverResult } from 'bentocache/types'
43+
import type { CreateDriverResult } from 'verrou/types'
7444

75-
export function myDriver(options: MyDriverOptions): CreateDriverResult<MyDriver> {
76-
return {
77-
options,
78-
factory: (config: MyDriverOptions) => new MyDriver(config)
79-
}
45+
export function myStore(config: MyStoreOptions): CreateDriverResult<MyStoreOptions> {
46+
return { config, factory: () => new MyDriver(config) }
8047
}
8148
```
8249

83-
Finally, you can use your driver when creating a new instance of Bentocache:
50+
Finally, you can use your driver when creating a new instance of Verrou:
8451

8552
```ts
86-
import { BentoCache, bentostore } from 'bentocache'
53+
import { Verrou } from 'verrou'
54+
import { myStore } from './my_store.js'
8755

88-
const bento = new BentoCache({
56+
const verrou = new Verrou({
8957
default: 'myStore',
9058
stores: {
91-
myStore: bentostore()
92-
.useL2Layer(myDriver({ /* Your driver options */ }))
59+
myStore: myStore({ /* Your driver options */ })
9360
}
9461
})
9562
```
9663

9764
## Tests
9865

99-
If you want to test your driver and its compliance, Bentocache is shipped with a test suite for [Japa](https://japa.dev/docs) that you can use. Note that you will also need to have `@japa/assert` installed. Then, you can use it like this:
66+
If you want to test your driver and its compliance, Verrou is shipped with a test suite for [Japa](https://japa.dev/docs) that you can use. Note that you will also need to have `@japa/assert` installed. Then, you can use it like this:
10067

10168
```ts
10269
// title: tests/my_driver.spec.ts
10370
import { test } from '@japa/runner'
104-
import { registerCacheDriverTestSuite } from 'bentocache/test_suite'
10571
import { MyDriver } from '../src/my_driver.js'
106-
107-
registerCacheDriverTestSuite({
108-
test,
109-
driver: MyDriver,
110-
config: {
111-
// Your driver options
112-
}
72+
import { registerStoreTestSuite } from 'verrou/test_suite'
73+
74+
test.group('My Store', (group) => {
75+
registerStoreTestSuite({
76+
test,
77+
store: MyStore,
78+
config: {
79+
// Your driver options
80+
}
81+
})
11382
})
11483
```
11584

0 commit comments

Comments
 (0)