Functions

Available Methods

Set

const myPayload = { id: 1, name: 'John', surname: 'Doe' }
await cache.set({ fileName: 'myFileName', key: 'myUniqueKey', payload: myPayload, ttl: 3600 })
// Stored as: myFileName hash_97c44f6f39acc990c8927e92168a61e2a3a1c9441679a1db76a1132562eb4ba6

Get

const data = await cache.get({ fileName: 'myFileName', key: 'myUniqueKey' });
// Gets cached data as: {"id":1,"name":"John","surname":"Doe"}

Get Files

Code
const files = cache.files()
Response
[
  { 
    "name": "myFileNameFirst hash_132d085c88b595f1ef63d51afcc700028145f194732ae460aaec04f574c5c5de",
    "size": { 
      "bytes": 75,
      "megabytes": 0.00007152557373046875
    },
    "ttl": 60,
    "expiration": 1710405034332,
    "expires_in": 59.997
  },
  { 
    "name": "myFileNameSecond hash_132d085c88b595f1ef63d51afcc700028145f194732ae460aaec04f574c5c5de",
    "size": {
      "bytes": 75,
      "megabytes": 0.00007152557373046875
    },
    "ttl": 60,
    "expiration": 1710405034334,
    "expires_in": 59.998
  }
]

Flush all

await cache.flushAll();
// Deletes all cached files

Flush by Regex

Code
await cache.flushByRegex('myFileName');
// or for multiple matches in file name
await cache.flushByRegex('myFileName', 'secondMatchValue');
Example: Single
await cache.set({ fileName: 'myFileName', key: 'myUniqueKey', payload: myPayload }) // Will delete
await cache.set({ fileName: 'myFileName', key: 'myUniqueKey', payload: myPayload }) // Will delete
await cache.set({ fileName: 'myFileNameDifferent', key: 'myUniqueKey', payload: myPayload }) // Will not delete
await cache.flushByRegex('myFileName');
Example: Multi
await cache.set({ fileName: 'john doe', key: 'myUniqueKey', payload: myPayload }) // Will not delete
await cache.set({ fileName: 'john doe engineer', key: 'myUniqueKey', payload: myPayload }) // Will delete
await cache.flushByRegex('john', 'engineer');

Option enableMonitoring is set to true

Get Logs

Code
const logs = cache.monitoring?.get()
Response
{
    "logs": [
        {
          "id": "number",
          "bytes": "number",
          "megabytes": "number",
          "storedFilesCount": "number",
          "date": "Date",
          "count": {
            "success": {
              "set": "number",
              "get": "number",
              "invalidate": "number",
              "validateFile": "number",
              "flushByRegex": "number",
              "flushAll": "number"
                },
            "error": {
              "set": "number",
              "get": "number",
              "invalidate": "number",
              "validateFile": "number",
              "flushByRegex": "number",
              "flushAll": "number"
                }
            }
        }
    ],
  "count": {
    "success": {
      "set": "number",
      "get": "number",
      "invalidate": "number",
      "validateFile": "number",
      "flushByRegex": "number",
      "flushAll": "number"
    },
    "error": {
      "set": "number",
      "get": "number",
      "invalidate": "number",
      "validateFile": "number",
      "flushByRegex": "number",
      "flushAll": "number"
    }
  }
}

Reset Logs

cache.monitoring?.reset()