flat-cache 6.1.0 → 6.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [<img align="center" src="https://cacheable.org/logo.svg" alt="Cacheable" />](https://github.com/jaredwray/cacheable)
1
+ [<img align="center" src="https://cacheable.org/symbol.svg" alt="Cacheable" />](https://github.com/jaredwray/cacheable)
2
2
 
3
3
  # flat-cache
4
4
  > A simple key/value storage using files to persist the data
@@ -7,16 +7,18 @@
7
7
  [![tests](https://github.com/jaredwray/cacheable/actions/workflows/tests.yml/badge.svg)](https://github.com/jaredwray/cacheable/actions/workflows/tests.yml)
8
8
  [![npm](https://img.shields.io/npm/dm/flat-cache.svg)](https://www.npmjs.com/package/flat-cache)
9
9
  [![npm](https://img.shields.io/npm/v/flat-cache)](https://www.npmjs.com/package/flat-cache)
10
- [![GitHub](https://img.shields.io/github/license/jaredwray/cacheable)](https://github.com/jaredwray/cacheable/blob/main/LICENSE)
10
+ [![license](https://img.shields.io/github/license/jaredwray/cacheable)](https://github.com/jaredwray/cacheable/blob/main/LICENSE)
11
11
 
12
12
  # Features
13
13
  - A simple key/value storage using files to persist the data
14
14
  - Uses a in-memory cache (via `CacheableMemory`) as the primary storage and then persists the data to disk
15
15
  - Automatically saves the data to disk via `persistInterval` setting. Off By Default
16
+ - Uses `expirationInterval` to check for expired items in the cache. If it is not set it will do a lazy check on `get` or `getKey`
16
17
  - Easily Loads the data from disk and into memory with `load` or `loadFile`
17
18
  - Uses `ttl` and `lruSize` to manage the cache and persist the data
18
19
  - Only saves the data to disk if the data has changed even when using `persistInterval` or calling `save()`
19
20
  - Uses `flatted` to parse and stringify the data by default but can be overridden using `parse` and `stringify` in options
21
+ - ESM and CommonJS support with TypeScript typings and maintained regularly!
20
22
 
21
23
  # Table of Contents
22
24
  - [Installation](#installation)
@@ -117,8 +119,8 @@ In version 6 we attempted to keep as much as the functionality as possible which
117
119
  - `persistInterval?` - The interval to save the data to disk. Default is `0` which means no persistence
118
120
  - `cacheDir?` - The directory to save the cache files. Default is `./cache`
119
121
  - `cacheId?` - The id of the cache. Default is `cache1`
120
- - `parse?` - The function to parse the data. Default is `flatted.parse`
121
- - `stringify?` - The function to stringify the data. Default is `flatted.stringify`
122
+ - `serialize?` - The function to parse the data. Default is `flatted.parse`
123
+ - `deserialize?` - The function to stringify the data. Default is `flatted.stringify`
122
124
 
123
125
  # API
124
126
 
package/dist/index.cjs CHANGED
@@ -35,7 +35,8 @@ __export(src_exports, {
35
35
  clearAll: () => clearAll,
36
36
  clearCacheById: () => clearCacheById,
37
37
  create: () => create,
38
- createFromFile: () => createFromFile
38
+ createFromFile: () => createFromFile,
39
+ default: () => FlatCacheDefault
39
40
  });
40
41
  module.exports = __toCommonJS(src_exports);
41
42
  var import_node_path = __toESM(require("path"), 1);
@@ -82,11 +83,11 @@ var FlatCache = class extends import_hookified.Hookified {
82
83
  this._persistInterval = options.persistInterval;
83
84
  this.startAutoPersist();
84
85
  }
85
- if (options?.parse) {
86
- this._parse = options.parse;
86
+ if (options?.deserialize) {
87
+ this._parse = options.deserialize;
87
88
  }
88
- if (options?.stringify) {
89
- this._stringify = options.stringify;
89
+ if (options?.serialize) {
90
+ this._stringify = options.serialize;
90
91
  }
91
92
  }
92
93
  /**
@@ -394,6 +395,12 @@ var FlatCache = class extends import_hookified.Hookified {
394
395
  }
395
396
  }
396
397
  };
398
+ var FlatCacheDefault = class {
399
+ static create = create;
400
+ static createFromFile = createFromFile;
401
+ static clearCacheById = clearCacheById;
402
+ static clearAll = clearAll;
403
+ };
397
404
  function create(options) {
398
405
  const cache = new FlatCache(options);
399
406
  cache.load();
package/dist/index.d.cts CHANGED
@@ -9,8 +9,8 @@ type FlatCacheOptions = {
9
9
  persistInterval?: number;
10
10
  cacheDir?: string;
11
11
  cacheId?: string;
12
- parse?: (data: string) => any;
13
- stringify?: (data: any) => string;
12
+ deserialize?: (data: string) => any;
13
+ serialize?: (data: any) => string;
14
14
  };
15
15
  declare enum FlatCacheEvents {
16
16
  SAVE = "save",
@@ -212,6 +212,12 @@ declare class FlatCache extends Hookified {
212
212
  */
213
213
  stopAutoPersist(): void;
214
214
  }
215
+ declare class FlatCacheDefault {
216
+ static create: typeof create;
217
+ static createFromFile: typeof createFromFile;
218
+ static clearCacheById: typeof clearCacheById;
219
+ static clearAll: typeof clearAll;
220
+ }
215
221
  /**
216
222
  * Load a cache identified by the given Id. If the element does not exists, then initialize an empty
217
223
  * cache storage.
@@ -245,4 +251,4 @@ declare function clearCacheById(cacheId: string, cacheDirectory?: string): void;
245
251
  */
246
252
  declare function clearAll(cacheDirectory?: string): void;
247
253
 
248
- export { FlatCache, FlatCacheEvents, type FlatCacheOptions, clearAll, clearCacheById, create, createFromFile };
254
+ export { FlatCache, FlatCacheEvents, type FlatCacheOptions, clearAll, clearCacheById, create, createFromFile, FlatCacheDefault as default };
package/dist/index.d.ts CHANGED
@@ -9,8 +9,8 @@ type FlatCacheOptions = {
9
9
  persistInterval?: number;
10
10
  cacheDir?: string;
11
11
  cacheId?: string;
12
- parse?: (data: string) => any;
13
- stringify?: (data: any) => string;
12
+ deserialize?: (data: string) => any;
13
+ serialize?: (data: any) => string;
14
14
  };
15
15
  declare enum FlatCacheEvents {
16
16
  SAVE = "save",
@@ -212,6 +212,12 @@ declare class FlatCache extends Hookified {
212
212
  */
213
213
  stopAutoPersist(): void;
214
214
  }
215
+ declare class FlatCacheDefault {
216
+ static create: typeof create;
217
+ static createFromFile: typeof createFromFile;
218
+ static clearCacheById: typeof clearCacheById;
219
+ static clearAll: typeof clearAll;
220
+ }
215
221
  /**
216
222
  * Load a cache identified by the given Id. If the element does not exists, then initialize an empty
217
223
  * cache storage.
@@ -245,4 +251,4 @@ declare function clearCacheById(cacheId: string, cacheDirectory?: string): void;
245
251
  */
246
252
  declare function clearAll(cacheDirectory?: string): void;
247
253
 
248
- export { FlatCache, FlatCacheEvents, type FlatCacheOptions, clearAll, clearCacheById, create, createFromFile };
254
+ export { FlatCache, FlatCacheEvents, type FlatCacheOptions, clearAll, clearCacheById, create, createFromFile, FlatCacheDefault as default };
package/dist/index.js CHANGED
@@ -43,11 +43,11 @@ var FlatCache = class extends Hookified {
43
43
  this._persistInterval = options.persistInterval;
44
44
  this.startAutoPersist();
45
45
  }
46
- if (options?.parse) {
47
- this._parse = options.parse;
46
+ if (options?.deserialize) {
47
+ this._parse = options.deserialize;
48
48
  }
49
- if (options?.stringify) {
50
- this._stringify = options.stringify;
49
+ if (options?.serialize) {
50
+ this._stringify = options.serialize;
51
51
  }
52
52
  }
53
53
  /**
@@ -355,6 +355,12 @@ var FlatCache = class extends Hookified {
355
355
  }
356
356
  }
357
357
  };
358
+ var FlatCacheDefault = class {
359
+ static create = create;
360
+ static createFromFile = createFromFile;
361
+ static clearCacheById = clearCacheById;
362
+ static clearAll = clearAll;
363
+ };
358
364
  function create(options) {
359
365
  const cache = new FlatCache(options);
360
366
  cache.load();
@@ -378,5 +384,6 @@ export {
378
384
  clearAll,
379
385
  clearCacheById,
380
386
  create,
381
- createFromFile
387
+ createFromFile,
388
+ FlatCacheDefault as default
382
389
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flat-cache",
3
- "version": "6.1.0",
3
+ "version": "6.1.1",
4
4
  "description": "A simple key/value storage using files to persist the data",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -12,33 +12,58 @@
12
12
  "import": "./dist/index.js"
13
13
  }
14
14
  },
15
- "repository": "https://github.com/jaredwray/cacheable.git",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/jaredwray/cacheable.git",
18
+ "directory": "packages/flat-cache"
19
+ },
16
20
  "author": "Jared Wray <me@jaredwray.com>",
17
21
  "license": "MIT",
18
22
  "private": false,
19
23
  "keywords": [
20
24
  "cache",
21
25
  "caching",
22
- "node",
23
- "nodejs",
24
26
  "cacheable",
25
- "cacheable-node-cache",
26
- "node-cache",
27
- "cacheable-node"
27
+ "flat-cache",
28
+ "flat",
29
+ "file",
30
+ "file-cache",
31
+ "file-caching",
32
+ "file-based-cache",
33
+ "file-persist",
34
+ "file-persistence",
35
+ "file-storage",
36
+ "file-system",
37
+ "file-management",
38
+ "filesystem-cache",
39
+ "disk-cache",
40
+ "cache-persistence",
41
+ "cache-persist",
42
+ "persistent-cache",
43
+ "persistent-storage",
44
+ "cache-to-file",
45
+ "cache-on-disk",
46
+ "cache-file",
47
+ "cache-expiration",
48
+ "cache-lifetime",
49
+ "data-persistence",
50
+ "data-storage",
51
+ "local-storage",
52
+ "file-system-cache"
28
53
  ],
29
54
  "devDependencies": {
30
- "@types/node": "^22.7.4",
31
- "@vitest/coverage-v8": "^2.1.1",
55
+ "@types/node": "^22.7.8",
56
+ "@vitest/coverage-v8": "^2.1.3",
32
57
  "rimraf": "^6.0.1",
33
58
  "tsup": "^8.3.0",
34
- "typescript": "^5.6.2",
35
- "vitest": "^2.1.1",
59
+ "typescript": "^5.6.3",
60
+ "vitest": "^2.1.3",
36
61
  "xo": "^0.59.3"
37
62
  },
38
63
  "dependencies": {
39
- "cacheable": "^1.7.1",
64
+ "cacheable": "^1.8.1",
40
65
  "flatted": "^3.3.1",
41
- "hookified": "^1.1.0"
66
+ "hookified": "^1.4.0"
42
67
  },
43
68
  "files": [
44
69
  "dist",