π Events
Listen to all events occurring in your cache.
Overview
Being able to listen to events occurring in our cache is very important in order to know whenever something expires, is deleted, or any other action you need.
To do this, we have developed the addEventListener method, which will help you understand everything that happens inside.
Set EventCode Sandbox
import { Cache } from "toolkitify/cache";
const cache = new Cache();
cache.addEventListener("set", (data) => {
// data: {"storage":"memory","key":"foo","value":"value-46524","uses":0,"ttl":60000,"expiresAt":"11/11/2025, 3:27:00 PM","msRemaining":60000}
})
Interfaces
| Parameter | Type | Required | Description |
|---|---|---|---|
event | Event | β | Event to listen to |
callback | Function | β | Callback to execute |
Event
| Parameter | Type |
|---|---|
event | set | get | delete | clear | expire |