modality-kit 0.14.4 → 0.14.5

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/dist/index.js CHANGED
@@ -5947,6 +5947,48 @@ class LruCache {
5947
5947
  return [...this._values.keys()];
5948
5948
  }
5949
5949
  }
5950
+ // src/simple-cache.ts
5951
+ class SimpleCache {
5952
+ lruCache;
5953
+ ttlMs;
5954
+ maxSize;
5955
+ constructor(options = {}) {
5956
+ this.ttlMs = options.ttlMs ?? 300000;
5957
+ this.maxSize = options.maxSize ?? 100;
5958
+ this.lruCache = new LruCache(this.maxSize);
5959
+ }
5960
+ set(key, data, ttlMs) {
5961
+ const entry = {
5962
+ data,
5963
+ timestamp: Date.now(),
5964
+ ttl: ttlMs ?? this.ttlMs
5965
+ };
5966
+ this.lruCache.set(key, entry);
5967
+ }
5968
+ get(key, ignoreTTL) {
5969
+ const entry = this.lruCache.get(key);
5970
+ if (!entry)
5971
+ return null;
5972
+ if (entry.ttl !== undefined && !ignoreTTL) {
5973
+ const age = Date.now() - entry.timestamp;
5974
+ if (age > entry.ttl) {
5975
+ this.lruCache.delete(key);
5976
+ return null;
5977
+ }
5978
+ }
5979
+ return entry.data;
5980
+ }
5981
+ has(key) {
5982
+ return this.lruCache.has(key);
5983
+ }
5984
+ delete(key) {
5985
+ const existed = this.lruCache.delete(key);
5986
+ return existed;
5987
+ }
5988
+ keys() {
5989
+ return this.lruCache.keys();
5990
+ }
5991
+ }
5950
5992
  export {
5951
5993
  withErrorHandling,
5952
5994
  loadVersion,
@@ -5959,6 +6001,7 @@ export {
5959
6001
  compressWithLanguageDetection as compressText,
5960
6002
  WebSocketClient,
5961
6003
  exports_schemas_symbol as SymbolTypes,
6004
+ SimpleCache,
5962
6005
  LruCache,
5963
6006
  JSONRPCUtils,
5964
6007
  JSONRPCManager,
@@ -23,3 +23,5 @@ export { ERROR_METHOD_NOT_FOUND } from "./jsonrpc-manager";
23
23
  export { isTestEnvironment } from "./util_tests/isTestEnvironment";
24
24
  export { WebSocketClient } from "./websocket-client";
25
25
  export { LruCache } from "./lruCache";
26
+ export { SimpleCache } from "./simple-cache";
27
+ export type { SimpleCacheOptions } from "./simple-cache";
@@ -0,0 +1,48 @@
1
+ /**
2
+ * SimpleCache - Unified caching utility with TTL and LRU support
3
+ *
4
+ * Supports two caching strategies:
5
+ * - TTL-based: Entries expire after specified time
6
+ * - LRU: Least Recently Used eviction when size limit reached
7
+ * - Hybrid: Both TTL and LRU can be enabled together
8
+ */
9
+ /**
10
+ * Cache options
11
+ */
12
+ export interface SimpleCacheOptions {
13
+ /** TTL in milliseconds. Set to undefined to disable TTL. Default: 300000 (5 minutes) */
14
+ ttlMs?: number;
15
+ /** Enable LRU eviction. Default: false */
16
+ enableLru?: boolean;
17
+ /** Max cache size for LRU. Default: 100 */
18
+ maxSize?: number;
19
+ }
20
+ /**
21
+ * SimpleCache - Generic cache supporting TTL and/or LRU eviction
22
+ */
23
+ export declare class SimpleCache<T> {
24
+ private lruCache;
25
+ private readonly ttlMs;
26
+ private readonly maxSize;
27
+ constructor(options?: SimpleCacheOptions);
28
+ /**
29
+ * Set cache entry
30
+ * @param key Cache key
31
+ * @param data Data to cache
32
+ * @param ttlMs Optional override for TTL (if undefined, uses instance TTL)
33
+ */
34
+ set(key: string, data: T, ttlMs?: number): void;
35
+ /**
36
+ * Get cache entry if still valid (not expired and not evicted by LRU)
37
+ */
38
+ get(key: string, ignoreTTL?: boolean): T | null;
39
+ /**
40
+ * Check if key exists and is valid
41
+ */
42
+ has(key: string): boolean;
43
+ /**
44
+ * Delete a specific key
45
+ */
46
+ delete(key: string): boolean;
47
+ keys(): string[];
48
+ }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.14.4",
2
+ "version": "0.14.5",
3
3
  "name": "modality-kit",
4
4
  "repository": {
5
5
  "type": "git",