@arkstack/cache 0.19.1 → 0.19.3

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
@@ -8,12 +8,12 @@ Cache module for Arkstack, providing a unified, driver based caching layer for t
8
8
 
9
9
  `@arkstack/cache` ships with four stores out of the box:
10
10
 
11
- | Driver | Backing store | Notes |
12
- | ---------- | ---------------------------- | ---------------------------------------- |
13
- | `memory` | in-process `Map` | default; great for dev and tests |
14
- | `file` | JSON files on disk | no external service required |
15
- | `redis` | Redis (via `ioredis`) | distributed; atomic counters |
16
- | `database` | a table via `@arkstack/database` | reuses your database connection |
11
+ | Driver | Backing store | Notes |
12
+ | ---------- | -------------------------------- | -------------------------------- |
13
+ | `memory` | in-process `Map` | default; great for dev and tests |
14
+ | `file` | JSON files on disk | no external service required |
15
+ | `redis` | Redis (via `ioredis`) | distributed; atomic counters |
16
+ | `database` | a table via `@arkstack/database` | reuses your database connection |
17
17
 
18
18
  ## Configuration
19
19
 
@@ -28,8 +28,15 @@ export default (): CacheConfig => ({
28
28
  prefix: env('CACHE_PREFIX', 'arkstack_cache_'),
29
29
  stores: {
30
30
  memory: { driver: 'memory' },
31
- file: { driver: 'file', path: path.join(Arkstack.rootDir(), './storage/framework/cache') },
32
- redis: { driver: 'redis', host: env('REDIS_HOST', '127.0.0.1'), port: env('REDIS_PORT', 6379) },
31
+ file: {
32
+ driver: 'file',
33
+ path: path.join(Arkstack.rootDir(), './storage/framework/cache'),
34
+ },
35
+ redis: {
36
+ driver: 'redis',
37
+ host: env('REDIS_HOST', '127.0.0.1'),
38
+ port: env('REDIS_PORT', 6379),
39
+ },
33
40
  database: { driver: 'database', table: 'cache' },
34
41
  },
35
42
  })
@@ -41,7 +48,7 @@ export default (): CacheConfig => ({
41
48
  import { Cache } from '@arkstack/cache'
42
49
 
43
50
  // default store
44
- await Cache.put('user:1', user, 60) // ttl in seconds
51
+ await Cache.put('user:1', user, 60) // ttl in seconds
45
52
  await Cache.get('user:1')
46
53
  await Cache.forget('user:1')
47
54
 
@@ -63,7 +70,9 @@ The ttl accepts a number of seconds, a `Date`, or `null` (forever).
63
70
  ```ts
64
71
  import { Cache, Store } from '@arkstack/cache'
65
72
 
66
- class TagStore extends Store { /* ... implement the Store contract ... */ }
73
+ class TagStore extends Store {
74
+ /* ... implement the Store contract ... */
75
+ }
67
76
 
68
77
  Cache.extend('tags', (config) => new TagStore(config))
69
78
  ```
@@ -378,18 +378,18 @@ var Repository = class {
378
378
  }
379
379
  /**
380
380
  * Determine whether an item exists in the cache and has not expired.
381
- *
382
- * @param key
383
- * @returns
381
+ *
382
+ * @param key
383
+ * @returns
384
384
  */
385
385
  async has(key) {
386
386
  return await this.store.get(key) !== null;
387
387
  }
388
388
  /**
389
389
  * Determine whether an item is missing from the cache.
390
- *
391
- * @param key
392
- * @returns
390
+ *
391
+ * @param key
392
+ * @returns
393
393
  */
394
394
  async missing(key) {
395
395
  return !await this.has(key);
@@ -397,9 +397,9 @@ var Repository = class {
397
397
  /**
398
398
  * Retrieve an item from the cache, falling back to `defaultValue` (which may
399
399
  * be a callback) when the item is absent.
400
- *
401
- * @param key
402
- * @returns
400
+ *
401
+ * @param key
402
+ * @returns
403
403
  */
404
404
  async get(key, defaultValue = null) {
405
405
  const value = await this.store.get(key);
@@ -408,10 +408,10 @@ var Repository = class {
408
408
  }
409
409
  /**
410
410
  * Retrieve an item and delete it from the cache in a single call.
411
- *
412
- * @param key
413
- * @param defaultValue
414
- * @returns
411
+ *
412
+ * @param key
413
+ * @param defaultValue
414
+ * @returns
415
415
  */
416
416
  async pull(key, defaultValue = null) {
417
417
  const value = await this.get(key, defaultValue);
@@ -421,10 +421,10 @@ var Repository = class {
421
421
  /**
422
422
  * Store an item in the cache. A `null`/omitted ttl stores the item forever;
423
423
  * a non positive ttl is a no-op that also forgets any existing entry.
424
- *
425
- * @param key
426
- * @param defaultValue
427
- * @returns
424
+ *
425
+ * @param key
426
+ * @param defaultValue
427
+ * @returns
428
428
  */
429
429
  async put(key, value, ttl = null) {
430
430
  const seconds = ttlToSeconds(ttl);
@@ -436,10 +436,10 @@ var Repository = class {
436
436
  }
437
437
  /**
438
438
  * Alias for {@link put}.
439
- *
440
- * @param key
441
- * @param defaultValue
442
- * @returns
439
+ *
440
+ * @param key
441
+ * @param defaultValue
442
+ * @returns
443
443
  */
444
444
  async set(key, value, ttl = null) {
445
445
  return this.put(key, value, ttl);
@@ -447,10 +447,10 @@ var Repository = class {
447
447
  /**
448
448
  * Store an item only if it is not already present. Returns `false` when the
449
449
  * key already exists.
450
- *
451
- * @param key
452
- * @param defaultValue
453
- * @returns
450
+ *
451
+ * @param key
452
+ * @param defaultValue
453
+ * @returns
454
454
  */
455
455
  async add(key, value, ttl = null) {
456
456
  if (await this.has(key)) return false;
@@ -458,30 +458,30 @@ var Repository = class {
458
458
  }
459
459
  /**
460
460
  * Store an item that never expires.
461
- *
462
- * @param key
463
- * @param defaultValue
464
- * @returns
461
+ *
462
+ * @param key
463
+ * @param defaultValue
464
+ * @returns
465
465
  */
466
466
  async forever(key, value) {
467
467
  return this.store.forever(key, value);
468
468
  }
469
469
  /**
470
470
  * Increment a stored numeric value.
471
- *
472
- * @param key
473
- * @param defaultValue
474
- * @returns
471
+ *
472
+ * @param key
473
+ * @param defaultValue
474
+ * @returns
475
475
  */
476
476
  async increment(key, value = 1) {
477
477
  return this.store.increment(key, value);
478
478
  }
479
479
  /**
480
480
  * Decrement a stored numeric value.
481
- *
482
- * @param key
483
- * @param defaultValue
484
- * @returns
481
+ *
482
+ * @param key
483
+ * @param defaultValue
484
+ * @returns
485
485
  */
486
486
  async decrement(key, value = 1) {
487
487
  return this.store.decrement(key, value);
@@ -489,10 +489,10 @@ var Repository = class {
489
489
  /**
490
490
  * Get an item from the cache, or execute the callback, store its result for
491
491
  * the given ttl, and return it.
492
- *
493
- * @param key
494
- * @param defaultValue
495
- * @returns
492
+ *
493
+ * @param key
494
+ * @param defaultValue
495
+ * @returns
496
496
  */
497
497
  async remember(key, ttl, callback) {
498
498
  const existing = await this.store.get(key);
@@ -504,10 +504,10 @@ var Repository = class {
504
504
  /**
505
505
  * Get an item from the cache, or execute the callback and store its result
506
506
  * forever.
507
- *
508
- * @param key
509
- * @param defaultValue
510
- * @returns
507
+ *
508
+ * @param key
509
+ * @param defaultValue
510
+ * @returns
511
511
  */
512
512
  async rememberForever(key, callback) {
513
513
  const existing = await this.store.get(key);
@@ -518,50 +518,50 @@ var Repository = class {
518
518
  }
519
519
  /**
520
520
  * Alias for {@link rememberForever}.
521
- *
522
- * @param key
523
- * @param callback
524
- * @returns
521
+ *
522
+ * @param key
523
+ * @param callback
524
+ * @returns
525
525
  */
526
526
  async sear(key, callback) {
527
527
  return this.rememberForever(key, callback);
528
528
  }
529
529
  /**
530
530
  * Remove an item from the cache.
531
- *
532
- * @param key
533
- * @param callback
534
- * @returns
531
+ *
532
+ * @param key
533
+ * @param callback
534
+ * @returns
535
535
  */
536
536
  async forget(key) {
537
537
  return this.store.forget(key);
538
538
  }
539
539
  /**
540
540
  * Alias for {@link forget}.
541
- *
542
- * @param key
543
- * @param callback
544
- * @returns
541
+ *
542
+ * @param key
543
+ * @param callback
544
+ * @returns
545
545
  */
546
546
  async delete(key) {
547
547
  return this.forget(key);
548
548
  }
549
549
  /**
550
550
  * Remove every item from the cache store.
551
- *
552
- * @param key
553
- * @param callback
554
- * @returns
551
+ *
552
+ * @param key
553
+ * @param callback
554
+ * @returns
555
555
  */
556
556
  async flush() {
557
557
  return this.store.flush();
558
558
  }
559
559
  /**
560
560
  * Alias for {@link flush}.
561
- *
562
- * @param key
563
- * @param callback
564
- * @returns
561
+ *
562
+ * @param key
563
+ * @param callback
564
+ * @returns
565
565
  */
566
566
  async clear() {
567
567
  return this.flush();
@@ -1,4 +1,4 @@
1
- import { t as Cache } from "../CacheManager-B2Iw5ceu.js";
1
+ import { t as Cache } from "../CacheManager-D7cFvMyi.js";
2
2
  import { Command } from "@h3ravel/musket";
3
3
  //#region src/commands/CacheClearCommand.ts
4
4
  /**
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as RedisStore, c as DatabaseStore, i as ttlToSeconds, l as Store, n as configure, o as MemoryStore, r as Repository, s as FileStore, t as Cache } from "./CacheManager-B2Iw5ceu.js";
1
+ import { a as RedisStore, c as DatabaseStore, i as ttlToSeconds, l as Store, n as configure, o as MemoryStore, r as Repository, s as FileStore, t as Cache } from "./CacheManager-D7cFvMyi.js";
2
2
  export { Cache, DatabaseStore, FileStore, MemoryStore, RedisStore, Repository, Store, configure, ttlToSeconds };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/cache",
3
- "version": "0.19.1",
3
+ "version": "0.19.3",
4
4
  "type": "module",
5
5
  "description": "Cache module for Arkstack, providing a unified, driver based caching layer for the framework.",
6
6
  "homepage": "https://arkstack.toneflix.net/guide/cache",
@@ -33,13 +33,13 @@
33
33
  "./package.json": "./package.json"
34
34
  },
35
35
  "dependencies": {
36
- "@arkstack/common": "^0.19.1"
36
+ "@arkstack/common": "^0.19.3"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@h3ravel/musket": "^2.2.13",
40
40
  "ioredis": "^5.4.1",
41
- "@arkstack/contract": "^0.19.1",
42
- "@arkstack/database": "^0.19.1"
41
+ "@arkstack/database": "^0.19.3",
42
+ "@arkstack/contract": "^0.19.3"
43
43
  },
44
44
  "peerDependenciesMeta": {
45
45
  "@arkstack/database": {