-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcache-service.ts
More file actions
69 lines (61 loc) · 1.84 KB
/
Copy pathcache-service.ts
File metadata and controls
69 lines (61 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
/**
* ICacheService - Cache Service Contract
*
* Defines the interface for cache operations in ObjectStack.
* Concrete implementations (Redis, Memory, etc.) should implement this interface.
*
* Follows Dependency Inversion Principle - plugins depend on this interface,
* not on concrete cache implementations.
*
* Aligned with CoreServiceName 'cache' in core-services.zod.ts.
*/
/**
* Cache statistics for monitoring and observability
*/
export interface CacheStats {
/** Total number of cache hits */
hits: number;
/** Total number of cache misses */
misses: number;
/** Number of keys currently stored */
keyCount: number;
/** Memory usage in bytes (if available) */
memoryUsage?: number;
}
export interface ICacheService {
/**
* Get a cached value by key
* @param key - Cache key
* @returns The cached value, or undefined if not found
*/
get<T = unknown>(key: string): Promise<T | undefined>;
/**
* Set a value in the cache
* @param key - Cache key
* @param value - Value to cache
* @param ttl - Optional time-to-live in seconds
*/
set<T = unknown>(key: string, value: T, ttl?: number): Promise<void>;
/**
* Delete a cached value by key
* @param key - Cache key
* @returns True if the key was deleted, false if it did not exist
*/
delete(key: string): Promise<boolean>;
/**
* Check if a key exists in the cache
* @param key - Cache key
* @returns True if the key exists
*/
has(key: string): Promise<boolean>;
/**
* Clear all entries from the cache
*/
clear(): Promise<void>;
/**
* Get cache statistics
* @returns Cache stats including hits, misses, and key count
*/
stats(): Promise<CacheStats>;
}