@nestjs-redisx/cache 1.0.0
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/LICENSE +21 -0
- package/README.md +50 -0
- package/dist/cache/api/decorators/cached.decorator.d.ts +152 -0
- package/dist/cache/api/decorators/cached.decorator.d.ts.map +1 -0
- package/dist/cache/api/decorators/invalidate-tags.decorator.d.ts +44 -0
- package/dist/cache/api/decorators/invalidate-tags.decorator.d.ts.map +1 -0
- package/dist/cache/application/ports/cache-service.port.d.ts +120 -0
- package/dist/cache/application/ports/cache-service.port.d.ts.map +1 -0
- package/dist/cache/application/ports/l1-cache-store.port.d.ts +56 -0
- package/dist/cache/application/ports/l1-cache-store.port.d.ts.map +1 -0
- package/dist/cache/application/ports/l2-cache-store.port.d.ts +98 -0
- package/dist/cache/application/ports/l2-cache-store.port.d.ts.map +1 -0
- package/dist/cache/application/services/cache-decorator-initializer.service.d.ts +25 -0
- package/dist/cache/application/services/cache-decorator-initializer.service.d.ts.map +1 -0
- package/dist/cache/application/services/cache.service.d.ts +106 -0
- package/dist/cache/application/services/cache.service.d.ts.map +1 -0
- package/dist/cache/application/services/warmup.service.d.ts +25 -0
- package/dist/cache/application/services/warmup.service.d.ts.map +1 -0
- package/dist/cache/domain/services/serializer.service.d.ts +29 -0
- package/dist/cache/domain/services/serializer.service.d.ts.map +1 -0
- package/dist/cache/domain/value-objects/cache-entry.vo.d.ts +69 -0
- package/dist/cache/domain/value-objects/cache-entry.vo.d.ts.map +1 -0
- package/dist/cache/domain/value-objects/cache-key.vo.d.ts +45 -0
- package/dist/cache/domain/value-objects/cache-key.vo.d.ts.map +1 -0
- package/dist/cache/domain/value-objects/tag.vo.d.ts +36 -0
- package/dist/cache/domain/value-objects/tag.vo.d.ts.map +1 -0
- package/dist/cache/domain/value-objects/tags.vo.d.ts +57 -0
- package/dist/cache/domain/value-objects/tags.vo.d.ts.map +1 -0
- package/dist/cache/domain/value-objects/ttl.vo.d.ts +58 -0
- package/dist/cache/domain/value-objects/ttl.vo.d.ts.map +1 -0
- package/dist/cache/infrastructure/adapters/l1-memory-store.adapter.d.ts +36 -0
- package/dist/cache/infrastructure/adapters/l1-memory-store.adapter.d.ts.map +1 -0
- package/dist/cache/infrastructure/adapters/l2-redis-store.adapter.d.ts +41 -0
- package/dist/cache/infrastructure/adapters/l2-redis-store.adapter.d.ts.map +1 -0
- package/dist/cache.plugin.d.ts +17 -0
- package/dist/cache.plugin.d.ts.map +1 -0
- package/dist/cache.service.d.ts +234 -0
- package/dist/cache.service.d.ts.map +1 -0
- package/dist/decorators/cache-evict.decorator.d.ts +97 -0
- package/dist/decorators/cache-evict.decorator.d.ts.map +1 -0
- package/dist/decorators/cache-put.decorator.d.ts +95 -0
- package/dist/decorators/cache-put.decorator.d.ts.map +1 -0
- package/dist/decorators/cache.interceptor.d.ts +63 -0
- package/dist/decorators/cache.interceptor.d.ts.map +1 -0
- package/dist/decorators/cacheable.decorator.d.ts +88 -0
- package/dist/decorators/cacheable.decorator.d.ts.map +1 -0
- package/dist/decorators/key-generator.util.d.ts +69 -0
- package/dist/decorators/key-generator.util.d.ts.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4199 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4152 -0
- package/dist/index.mjs.map +1 -0
- package/dist/invalidation/application/ports/event-invalidation.port.d.ts +28 -0
- package/dist/invalidation/application/ports/event-invalidation.port.d.ts.map +1 -0
- package/dist/invalidation/application/ports/invalidation-registry.port.d.ts +36 -0
- package/dist/invalidation/application/ports/invalidation-registry.port.d.ts.map +1 -0
- package/dist/invalidation/application/services/event-invalidation.service.d.ts +30 -0
- package/dist/invalidation/application/services/event-invalidation.service.d.ts.map +1 -0
- package/dist/invalidation/application/services/invalidation-registry.service.d.ts +17 -0
- package/dist/invalidation/application/services/invalidation-registry.service.d.ts.map +1 -0
- package/dist/invalidation/domain/entities/invalidation-rule.entity.d.ts +60 -0
- package/dist/invalidation/domain/entities/invalidation-rule.entity.d.ts.map +1 -0
- package/dist/invalidation/domain/value-objects/event-pattern.vo.d.ts +27 -0
- package/dist/invalidation/domain/value-objects/event-pattern.vo.d.ts.map +1 -0
- package/dist/invalidation/domain/value-objects/tag-template.vo.d.ts +34 -0
- package/dist/invalidation/domain/value-objects/tag-template.vo.d.ts.map +1 -0
- package/dist/invalidation/infrastructure/adapters/amqp-event-source.adapter.d.ts +51 -0
- package/dist/invalidation/infrastructure/adapters/amqp-event-source.adapter.d.ts.map +1 -0
- package/dist/invalidation/infrastructure/decorators/invalidate-on.decorator.d.ts +69 -0
- package/dist/invalidation/infrastructure/decorators/invalidate-on.decorator.d.ts.map +1 -0
- package/dist/key-builder.d.ts +199 -0
- package/dist/key-builder.d.ts.map +1 -0
- package/dist/serializers/index.d.ts +19 -0
- package/dist/serializers/index.d.ts.map +1 -0
- package/dist/serializers/json.serializer.d.ts +51 -0
- package/dist/serializers/json.serializer.d.ts.map +1 -0
- package/dist/serializers/msgpack.serializer.d.ts +67 -0
- package/dist/serializers/msgpack.serializer.d.ts.map +1 -0
- package/dist/serializers/serializer.interface.d.ts +36 -0
- package/dist/serializers/serializer.interface.d.ts.map +1 -0
- package/dist/shared/constants/index.d.ts +73 -0
- package/dist/shared/constants/index.d.ts.map +1 -0
- package/dist/shared/errors/index.d.ts +46 -0
- package/dist/shared/errors/index.d.ts.map +1 -0
- package/dist/shared/types/context-provider.interface.d.ts +58 -0
- package/dist/shared/types/context-provider.interface.d.ts.map +1 -0
- package/dist/shared/types/index.d.ts +259 -0
- package/dist/shared/types/index.d.ts.map +1 -0
- package/dist/stampede/application/ports/stampede-protection.port.d.ts +33 -0
- package/dist/stampede/application/ports/stampede-protection.port.d.ts.map +1 -0
- package/dist/stampede/infrastructure/stampede-protection.service.d.ts +30 -0
- package/dist/stampede/infrastructure/stampede-protection.service.d.ts.map +1 -0
- package/dist/strategies/eviction-strategy.interface.d.ts +39 -0
- package/dist/strategies/eviction-strategy.interface.d.ts.map +1 -0
- package/dist/strategies/fifo.strategy.d.ts +86 -0
- package/dist/strategies/fifo.strategy.d.ts.map +1 -0
- package/dist/strategies/index.d.ts +19 -0
- package/dist/strategies/index.d.ts.map +1 -0
- package/dist/strategies/lfu.strategy.d.ts +87 -0
- package/dist/strategies/lfu.strategy.d.ts.map +1 -0
- package/dist/strategies/lru.strategy.d.ts +78 -0
- package/dist/strategies/lru.strategy.d.ts.map +1 -0
- package/dist/swr/application/ports/swr-manager.port.d.ts +83 -0
- package/dist/swr/application/ports/swr-manager.port.d.ts.map +1 -0
- package/dist/swr/infrastructure/swr-manager.service.d.ts +30 -0
- package/dist/swr/infrastructure/swr-manager.service.d.ts.map +1 -0
- package/dist/tags/application/ports/tag-index.port.d.ts +55 -0
- package/dist/tags/application/ports/tag-index.port.d.ts.map +1 -0
- package/dist/tags/infrastructure/repositories/tag-index.repository.d.ts +37 -0
- package/dist/tags/infrastructure/repositories/tag-index.repository.d.ts.map +1 -0
- package/dist/tags/infrastructure/scripts/lua-scripts.d.ts +25 -0
- package/dist/tags/infrastructure/scripts/lua-scripts.d.ts.map +1 -0
- package/dist/tags/infrastructure/services/lua-script-loader.service.d.ts +44 -0
- package/dist/tags/infrastructure/services/lua-script-loader.service.d.ts.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main cache service implementation.
|
|
3
|
+
* Orchestrates L1/L2 caching with stampede protection, SWR, and tag invalidation.
|
|
4
|
+
*/
|
|
5
|
+
import { IRedisDriver } from '@nestjs-redisx/core';
|
|
6
|
+
import { CacheSetOptions, CacheGetOrSetOptions, CacheStats, ICachePluginOptions } from '../../../shared/types';
|
|
7
|
+
import { IStampedeProtection } from '../../../stampede/application/ports/stampede-protection.port';
|
|
8
|
+
import { ISwrManager } from '../../../swr/application/ports/swr-manager.port';
|
|
9
|
+
import { ITagIndex } from '../../../tags/application/ports/tag-index.port';
|
|
10
|
+
import { ICacheService } from '../ports/cache-service.port';
|
|
11
|
+
import { IL1CacheStore } from '../ports/l1-cache-store.port';
|
|
12
|
+
import { IL2CacheStore } from '../ports/l2-cache-store.port';
|
|
13
|
+
interface IMetricsService {
|
|
14
|
+
incrementCounter(name: string, labels?: Record<string, string>, value?: number): void;
|
|
15
|
+
setGauge(name: string, value: number, labels?: Record<string, string>): void;
|
|
16
|
+
}
|
|
17
|
+
interface ISpan {
|
|
18
|
+
setAttribute(key: string, value: unknown): this;
|
|
19
|
+
addEvent(name: string, attributes?: Record<string, unknown>): this;
|
|
20
|
+
setStatus(status: 'OK' | 'ERROR'): this;
|
|
21
|
+
recordException(error: Error): this;
|
|
22
|
+
end(): void;
|
|
23
|
+
}
|
|
24
|
+
interface ITracingService {
|
|
25
|
+
startSpan(name: string, options?: {
|
|
26
|
+
kind?: string;
|
|
27
|
+
attributes?: Record<string, unknown>;
|
|
28
|
+
}): ISpan;
|
|
29
|
+
}
|
|
30
|
+
export declare class CacheService implements ICacheService {
|
|
31
|
+
private readonly driver;
|
|
32
|
+
private readonly l1Store;
|
|
33
|
+
private readonly l2Store;
|
|
34
|
+
private readonly stampede;
|
|
35
|
+
private readonly tagIndex;
|
|
36
|
+
private readonly swrManager;
|
|
37
|
+
private readonly options;
|
|
38
|
+
private readonly metrics?;
|
|
39
|
+
private readonly tracing?;
|
|
40
|
+
private readonly logger;
|
|
41
|
+
private readonly l1Enabled;
|
|
42
|
+
private readonly l2Enabled;
|
|
43
|
+
private readonly stampedeEnabled;
|
|
44
|
+
private readonly swrEnabled;
|
|
45
|
+
private readonly tagsEnabled;
|
|
46
|
+
private readonly keyPrefix;
|
|
47
|
+
constructor(driver: IRedisDriver, l1Store: IL1CacheStore, l2Store: IL2CacheStore, stampede: IStampedeProtection, tagIndex: ITagIndex, swrManager: ISwrManager, options: ICachePluginOptions, metrics?: IMetricsService | undefined, tracing?: ITracingService | undefined);
|
|
48
|
+
get<T>(key: string): Promise<T | null>;
|
|
49
|
+
set<T>(key: string, value: T, options?: CacheSetOptions): Promise<void>;
|
|
50
|
+
getOrSet<T>(key: string, loader: () => Promise<T>, options?: CacheGetOrSetOptions): Promise<T>;
|
|
51
|
+
/**
|
|
52
|
+
* Loads value with stampede protection if enabled.
|
|
53
|
+
*
|
|
54
|
+
* @param key - Normalized cache key
|
|
55
|
+
* @param loader - Function to load value
|
|
56
|
+
* @param options - Cache options
|
|
57
|
+
* @returns Loaded value
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
private loadWithStampede;
|
|
61
|
+
delete(key: string): Promise<boolean>;
|
|
62
|
+
deleteMany(keys: string[]): Promise<number>;
|
|
63
|
+
clear(): Promise<void>;
|
|
64
|
+
has(key: string): Promise<boolean>;
|
|
65
|
+
invalidateTag(tag: string): Promise<number>;
|
|
66
|
+
invalidateTags(tags: string[]): Promise<number>;
|
|
67
|
+
getKeysByTag(tag: string): Promise<string[]>;
|
|
68
|
+
getMany<T>(keys: string[]): Promise<Array<T | null>>;
|
|
69
|
+
setMany<T>(entries: Array<{
|
|
70
|
+
key: string;
|
|
71
|
+
value: T;
|
|
72
|
+
ttl?: number;
|
|
73
|
+
tags?: string[];
|
|
74
|
+
}>): Promise<void>;
|
|
75
|
+
ttl(key: string): Promise<number>;
|
|
76
|
+
getStats(): Promise<CacheStats>;
|
|
77
|
+
invalidateByPattern(pattern: string): Promise<number>;
|
|
78
|
+
/**
|
|
79
|
+
* Validates and normalizes cache key using CacheKey value object.
|
|
80
|
+
*
|
|
81
|
+
* @param rawKey - Raw key string
|
|
82
|
+
* @returns Normalized key string (without prefix - prefix added by L2 store)
|
|
83
|
+
* @throws CacheKeyError if validation fails
|
|
84
|
+
*
|
|
85
|
+
* @private
|
|
86
|
+
*/
|
|
87
|
+
private validateAndNormalizeKey;
|
|
88
|
+
/**
|
|
89
|
+
* Enriches a normalized key with context values.
|
|
90
|
+
* Appends global context keys and per-call varyBy values as key suffix.
|
|
91
|
+
* Uses a marker (_ctx_) to prevent double-enrichment in internal call chains.
|
|
92
|
+
*
|
|
93
|
+
* @param normalizedKey - Already validated and normalized cache key
|
|
94
|
+
* @param varyBy - Optional per-call context overrides
|
|
95
|
+
* @returns Enriched key with context suffix, or original key if no context
|
|
96
|
+
* @private
|
|
97
|
+
*/
|
|
98
|
+
private enrichKeyWithContext;
|
|
99
|
+
/**
|
|
100
|
+
* Sanitizes a value for use in cache key (removes non-allowed characters).
|
|
101
|
+
* @private
|
|
102
|
+
*/
|
|
103
|
+
private sanitizeForKey;
|
|
104
|
+
}
|
|
105
|
+
export {};
|
|
106
|
+
//# sourceMappingURL=cache.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.service.d.ts","sourceRoot":"","sources":["../../../../src/cache/application/services/cache.service.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAgB,YAAY,EAAa,MAAM,qBAAqB,CAAC;AAI5E,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC/G,OAAO,EAAE,mBAAmB,EAAE,MAAM,8DAA8D,CAAC;AACnG,OAAO,EAAE,WAAW,EAAE,MAAM,iDAAiD,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,gDAAgD,CAAC;AAM3E,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAK7D,UAAU,eAAe;IACvB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtF,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CA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AO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAyDpD,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,CAAC,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IA8CnG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAmBjC,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC;IAY/B,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAmC3D;;;;;;;;OAQG;IACH,OAAO,CAAC,uBAAuB;IAsB/B;;;;;;;;;OASG;IACH,OAAO,CAAC,oBAAoB;IAsC5B;;;OAGG;IACH,OAAO,CAAC,cAAc;CAGvB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache warmup service.
|
|
3
|
+
* Loads specified keys into cache on application startup.
|
|
4
|
+
*/
|
|
5
|
+
import { OnModuleInit } from '@nestjs/common';
|
|
6
|
+
import { ICachePluginOptions } from '../../../shared/types';
|
|
7
|
+
import { ICacheService } from '../ports/cache-service.port';
|
|
8
|
+
export declare class WarmupService implements OnModuleInit {
|
|
9
|
+
private readonly cacheService;
|
|
10
|
+
private readonly options;
|
|
11
|
+
private readonly logger;
|
|
12
|
+
private readonly enabled;
|
|
13
|
+
private readonly keys;
|
|
14
|
+
private readonly concurrency;
|
|
15
|
+
constructor(cacheService: ICacheService, options: ICachePluginOptions);
|
|
16
|
+
onModuleInit(): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Warms up a single cache key.
|
|
19
|
+
*
|
|
20
|
+
* @param warmupKey - Warmup key configuration
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
private warmupKey;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=warmup.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warmup.service.d.ts","sourceRoot":"","sources":["../../../../src/cache/application/services/warmup.service.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAA8B,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG1E,OAAO,EAAE,mBAAmB,EAAc,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,qBACa,aAAc,YAAW,YAAY;IAOvB,OAAO,CAAC,QAAQ,CAAC,YAAY;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAPxD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkC;IACzD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAe;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;gBAGK,YAAY,EAAE,aAAa,EACpB,OAAO,EAAE,mBAAmB;IAOvE,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IA8BnC;;;;;OAKG;YACW,SAAS;CAexB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serializer service for cache values.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Serializer {
|
|
5
|
+
/**
|
|
6
|
+
* Serializes value to string.
|
|
7
|
+
*
|
|
8
|
+
* @param value - Value to serialize
|
|
9
|
+
* @returns Serialized string
|
|
10
|
+
* @throws SerializationError if serialization fails
|
|
11
|
+
*/
|
|
12
|
+
serialize<T>(value: T): string;
|
|
13
|
+
/**
|
|
14
|
+
* Deserializes string to value.
|
|
15
|
+
*
|
|
16
|
+
* @param serialized - Serialized string
|
|
17
|
+
* @returns Deserialized value
|
|
18
|
+
* @throws SerializationError if deserialization fails
|
|
19
|
+
*/
|
|
20
|
+
deserialize<T>(serialized: string): T;
|
|
21
|
+
/**
|
|
22
|
+
* Safely tries to deserialize, returns null on error.
|
|
23
|
+
*
|
|
24
|
+
* @param serialized - Serialized string
|
|
25
|
+
* @returns Deserialized value or null
|
|
26
|
+
*/
|
|
27
|
+
tryDeserialize<T>(serialized: string): T | null;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=serializer.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer.service.d.ts","sourceRoot":"","sources":["../../../../src/cache/domain/services/serializer.service.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,qBACa,UAAU;IACrB;;;;;;OAMG;IACH,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM;IAQ9B;;;;;;OAMG;IACH,WAAW,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC;IAQrC;;;;;OAKG;IACH,cAAc,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI;CAOhD"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CacheEntry value object.
|
|
3
|
+
* Wraps cached value with metadata.
|
|
4
|
+
*/
|
|
5
|
+
export declare class CacheEntry<T> {
|
|
6
|
+
readonly value: T;
|
|
7
|
+
readonly cachedAt: number;
|
|
8
|
+
readonly ttl: number;
|
|
9
|
+
readonly tags?: string[] | undefined;
|
|
10
|
+
private constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Creates a cache entry.
|
|
13
|
+
*
|
|
14
|
+
* @param value - Value to cache
|
|
15
|
+
* @param ttl - TTL in seconds
|
|
16
|
+
* @param tags - Optional tags
|
|
17
|
+
* @returns CacheEntry instance
|
|
18
|
+
*/
|
|
19
|
+
static create<T>(value: T, ttl: number, tags?: string[]): CacheEntry<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Checks if entry is expired.
|
|
22
|
+
*
|
|
23
|
+
* @returns true if expired, false otherwise
|
|
24
|
+
*/
|
|
25
|
+
isExpired(): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Gets time until expiration in milliseconds.
|
|
28
|
+
*
|
|
29
|
+
* @returns Milliseconds until expiration (0 if expired)
|
|
30
|
+
*/
|
|
31
|
+
getTimeToLive(): number;
|
|
32
|
+
/**
|
|
33
|
+
* Gets age of entry in milliseconds.
|
|
34
|
+
*
|
|
35
|
+
* @returns Age in milliseconds
|
|
36
|
+
*/
|
|
37
|
+
getAge(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Checks if entry has a specific tag.
|
|
40
|
+
*
|
|
41
|
+
* @param tag - Tag to check
|
|
42
|
+
* @returns true if entry has the tag
|
|
43
|
+
*/
|
|
44
|
+
hasTag(tag: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Serializes entry to JSON.
|
|
47
|
+
*
|
|
48
|
+
* @returns JSON representation
|
|
49
|
+
*/
|
|
50
|
+
toJSON(): {
|
|
51
|
+
value: T;
|
|
52
|
+
cachedAt: number;
|
|
53
|
+
ttl: number;
|
|
54
|
+
tags?: string[];
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Deserializes entry from JSON.
|
|
58
|
+
*
|
|
59
|
+
* @param json - JSON representation
|
|
60
|
+
* @returns CacheEntry instance
|
|
61
|
+
*/
|
|
62
|
+
static fromJSON<T>(json: {
|
|
63
|
+
value: T;
|
|
64
|
+
cachedAt: number;
|
|
65
|
+
ttl: number;
|
|
66
|
+
tags?: string[];
|
|
67
|
+
}): CacheEntry<T>;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=cache-entry.vo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-entry.vo.d.ts","sourceRoot":"","sources":["../../../../src/cache/domain/value-objects/cache-entry.vo.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qBAAa,UAAU,CAAC,CAAC;aAEL,KAAK,EAAE,CAAC;aACR,QAAQ,EAAE,MAAM;aAChB,GAAG,EAAE,MAAM;aACX,IAAI,CAAC,EAAE,MAAM,EAAE;IAJjC,OAAO;IAOP;;;;;;;OAOG;IACH,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC;IAIvE;;;;OAIG;IACH,SAAS,IAAI,OAAO;IAKpB;;;;OAIG;IACH,aAAa,IAAI,MAAM;IAMvB;;;;OAIG;IACH,MAAM,IAAI,MAAM;IAIhB;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAI5B;;;;OAIG;IACH,MAAM,IAAI;QACR,KAAK,EAAE,CAAC,CAAC;QACT,QAAQ,EAAE,MAAM,CAAC;QACjB,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;KACjB;IASD;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE;QAAE,KAAK,EAAE,CAAC,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,UAAU,CAAC,CAAC,CAAC;CAGtG"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CacheKey value object.
|
|
3
|
+
* Validates and builds cache keys with prefix, version, and validation.
|
|
4
|
+
*/
|
|
5
|
+
export interface ICacheKeyOptions {
|
|
6
|
+
maxLength?: number;
|
|
7
|
+
prefix?: string;
|
|
8
|
+
version?: string;
|
|
9
|
+
separator?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class CacheKey {
|
|
12
|
+
private readonly rawKey;
|
|
13
|
+
private readonly options;
|
|
14
|
+
private constructor();
|
|
15
|
+
/**
|
|
16
|
+
* Creates a validated cache key.
|
|
17
|
+
*
|
|
18
|
+
* @param key - Raw key
|
|
19
|
+
* @param options - Key options
|
|
20
|
+
* @returns CacheKey instance
|
|
21
|
+
* @throws CacheKeyError if validation fails
|
|
22
|
+
*/
|
|
23
|
+
static create(key: string, options?: ICacheKeyOptions): CacheKey;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the full cache key with prefix and version.
|
|
26
|
+
*/
|
|
27
|
+
toString(): string;
|
|
28
|
+
/**
|
|
29
|
+
* Returns the raw key without prefix/version.
|
|
30
|
+
*/
|
|
31
|
+
getRaw(): string;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the prefix.
|
|
34
|
+
*/
|
|
35
|
+
getPrefix(): string;
|
|
36
|
+
/**
|
|
37
|
+
* Returns the version.
|
|
38
|
+
*/
|
|
39
|
+
getVersion(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Checks equality with another CacheKey.
|
|
42
|
+
*/
|
|
43
|
+
equals(other: CacheKey): boolean;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=cache-key.vo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-key.vo.d.ts","sourceRoot":"","sources":["../../../../src/cache/domain/value-objects/cache-key.vo.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AASD,qBAAa,QAAQ;IAEjB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAF1B,OAAO;IAKP;;;;;;;OAOG;IACH,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,QAAQ;IAmCpE;;OAEG;IACH,QAAQ,IAAI,MAAM;IAIlB;;OAEG;IACH,MAAM,IAAI,MAAM;IAIhB;;OAEG;IACH,SAAS,IAAI,MAAM;IAInB;;OAEG;IACH,UAAU,IAAI,MAAM;IAIpB;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO;CAGjC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tag value object.
|
|
3
|
+
* Validates and normalizes cache tags for invalidation.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Tag {
|
|
6
|
+
private readonly value;
|
|
7
|
+
private constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Creates a validated tag.
|
|
10
|
+
*
|
|
11
|
+
* @param value - Tag value
|
|
12
|
+
* @param maxLength - Maximum tag length (default: 128)
|
|
13
|
+
* @returns Tag instance
|
|
14
|
+
* @throws CacheError if validation fails
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const tag = Tag.create('users');
|
|
19
|
+
* const productTag = Tag.create('product:123');
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
static create(value: string, maxLength?: number): Tag;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the tag value.
|
|
25
|
+
*/
|
|
26
|
+
toString(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Returns the raw tag value.
|
|
29
|
+
*/
|
|
30
|
+
getRaw(): string;
|
|
31
|
+
/**
|
|
32
|
+
* Checks equality with another tag.
|
|
33
|
+
*/
|
|
34
|
+
equals(other: Tag): boolean;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=tag.vo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag.vo.d.ts","sourceRoot":"","sources":["../../../../src/cache/domain/value-objects/tag.vo.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,qBAAa,GAAG;IACM,OAAO,CAAC,QAAQ,CAAC,KAAK;IAA1C,OAAO;IAEP;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,GAAE,MAA2B,GAAG,GAAG;IAgCzE;;OAEG;IACH,QAAQ,IAAI,MAAM;IAIlB;;OAEG;IACH,MAAM,IAAI,MAAM;IAIhB;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO;CAG5B"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tags collection value object.
|
|
3
|
+
* Validates and manages a collection of tags with deduplication.
|
|
4
|
+
*/
|
|
5
|
+
import { Tag } from './tag.vo';
|
|
6
|
+
export declare class Tags {
|
|
7
|
+
private readonly tags;
|
|
8
|
+
private constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Creates a validated tags collection.
|
|
11
|
+
*
|
|
12
|
+
* @param values - Array of tag values
|
|
13
|
+
* @param maxTags - Maximum number of tags (default: 10)
|
|
14
|
+
* @returns Tags instance
|
|
15
|
+
* @throws CacheError if validation fails
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const tags = Tags.create(['users', 'product:123']);
|
|
20
|
+
* const singleTag = Tags.create(['cache']);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
static create(values: string[], maxTags?: number): Tags;
|
|
24
|
+
/**
|
|
25
|
+
* Creates empty tags collection.
|
|
26
|
+
*/
|
|
27
|
+
static empty(): Tags;
|
|
28
|
+
/**
|
|
29
|
+
* Returns array of tag strings.
|
|
30
|
+
*/
|
|
31
|
+
toStrings(): string[];
|
|
32
|
+
/**
|
|
33
|
+
* Returns array of Tag objects.
|
|
34
|
+
*/
|
|
35
|
+
toArray(): Tag[];
|
|
36
|
+
/**
|
|
37
|
+
* Returns number of tags.
|
|
38
|
+
*/
|
|
39
|
+
size(): number;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if collection contains a specific tag.
|
|
42
|
+
*/
|
|
43
|
+
has(tag: Tag): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Checks if collection is empty.
|
|
46
|
+
*/
|
|
47
|
+
isEmpty(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Iterates over tags.
|
|
50
|
+
*/
|
|
51
|
+
forEach(callback: (tag: Tag, index: number) => void): void;
|
|
52
|
+
/**
|
|
53
|
+
* Maps over tags.
|
|
54
|
+
*/
|
|
55
|
+
map<T>(callback: (tag: Tag, index: number) => T): T[];
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=tags.vo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tags.vo.d.ts","sourceRoot":"","sources":["../../../../src/cache/domain/value-objects/tags.vo.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAK/B,qBAAa,IAAI;IACK,OAAO,CAAC,QAAQ,CAAC,IAAI;IAAzC,OAAO;IAEP;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,MAAyB,GAAG,IAAI;IAkBzE;;OAEG;IACH,MAAM,CAAC,KAAK,IAAI,IAAI;IAIpB;;OAEG;IACH,SAAS,IAAI,MAAM,EAAE;IAIrB;;OAEG;IACH,OAAO,IAAI,GAAG,EAAE;IAIhB;;OAEG;IACH,IAAI,IAAI,MAAM;IAId;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO;IAItB;;OAEG;IACH,OAAO,IAAI,OAAO;IAIlB;;OAEG;IACH,OAAO,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAI1D;;OAEG;IACH,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC,EAAE;CAGtD"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TTL (Time To Live) value object.
|
|
3
|
+
* Validates and normalizes TTL values.
|
|
4
|
+
*/
|
|
5
|
+
export declare class TTL {
|
|
6
|
+
private readonly seconds;
|
|
7
|
+
private constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Creates a TTL value object.
|
|
10
|
+
*
|
|
11
|
+
* @param seconds - TTL in seconds
|
|
12
|
+
* @param maxTtl - Maximum allowed TTL
|
|
13
|
+
* @returns TTL instance
|
|
14
|
+
* @throws CacheError if validation fails
|
|
15
|
+
*/
|
|
16
|
+
static create(seconds: number, maxTtl?: number): TTL;
|
|
17
|
+
/**
|
|
18
|
+
* Creates TTL from milliseconds.
|
|
19
|
+
*
|
|
20
|
+
* @param milliseconds - TTL in milliseconds
|
|
21
|
+
* @param maxTtl - Maximum allowed TTL in seconds
|
|
22
|
+
* @returns TTL instance
|
|
23
|
+
*/
|
|
24
|
+
static fromMilliseconds(milliseconds: number, maxTtl?: number): TTL;
|
|
25
|
+
/**
|
|
26
|
+
* Returns TTL in seconds.
|
|
27
|
+
*/
|
|
28
|
+
toSeconds(): number;
|
|
29
|
+
/**
|
|
30
|
+
* Returns TTL in milliseconds.
|
|
31
|
+
*/
|
|
32
|
+
toMilliseconds(): number;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if TTL is less than another TTL.
|
|
35
|
+
*/
|
|
36
|
+
isLessThan(other: TTL): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Checks if TTL is greater than another TTL.
|
|
39
|
+
*/
|
|
40
|
+
isGreaterThan(other: TTL): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Returns the minimum of two TTLs.
|
|
43
|
+
*/
|
|
44
|
+
static min(a: TTL, b: TTL): TTL;
|
|
45
|
+
/**
|
|
46
|
+
* Returns the maximum of two TTLs.
|
|
47
|
+
*/
|
|
48
|
+
static max(a: TTL, b: TTL): TTL;
|
|
49
|
+
/**
|
|
50
|
+
* Checks equality with another TTL.
|
|
51
|
+
*/
|
|
52
|
+
equals(other: TTL): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Returns string representation.
|
|
55
|
+
*/
|
|
56
|
+
toString(): string;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=ttl.vo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ttl.vo.d.ts","sourceRoot":"","sources":["../../../../src/cache/domain/value-objects/ttl.vo.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,qBAAa,GAAG;IACM,OAAO,CAAC,QAAQ,CAAC,OAAO;IAA5C,OAAO;IAEP;;;;;;;OAOG;IACH,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,MAAgC,GAAG,GAAG;IAiB7E;;;;;;OAMG;IACH,MAAM,CAAC,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,GAAE,MAAgC,GAAG,GAAG;IAI5F;;OAEG;IACH,SAAS,IAAI,MAAM;IAInB;;OAEG;IACH,cAAc,IAAI,MAAM;IAIxB;;OAEG;IACH,UAAU,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO;IAI/B;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO;IAIlC;;OAEG;IACH,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,GAAG,GAAG;IAI/B;;OAEG;IACH,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,GAAG,GAAG;IAI/B;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO;IAI3B;;OAEG;IACH,QAAQ,IAAI,MAAM;CAGnB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L1 in-memory cache store implementation.
|
|
3
|
+
* Supports LRU and LFU eviction policies.
|
|
4
|
+
*/
|
|
5
|
+
import { ICachePluginOptions } from '../../../shared/types';
|
|
6
|
+
import { IL1CacheStore } from '../../application/ports/l1-cache-store.port';
|
|
7
|
+
import { CacheEntry } from '../../domain/value-objects/cache-entry.vo';
|
|
8
|
+
export declare class L1MemoryStoreAdapter implements IL1CacheStore {
|
|
9
|
+
private readonly options;
|
|
10
|
+
private readonly cache;
|
|
11
|
+
private head;
|
|
12
|
+
private tail;
|
|
13
|
+
private readonly maxSize;
|
|
14
|
+
private readonly defaultTtl;
|
|
15
|
+
private readonly evictionPolicy;
|
|
16
|
+
private hits;
|
|
17
|
+
private misses;
|
|
18
|
+
constructor(options: ICachePluginOptions);
|
|
19
|
+
get<T>(key: string): Promise<CacheEntry<T> | null>;
|
|
20
|
+
set<T>(key: string, entry: CacheEntry<T>, ttl?: number): Promise<void>;
|
|
21
|
+
delete(key: string): Promise<boolean>;
|
|
22
|
+
clear(): Promise<void>;
|
|
23
|
+
has(key: string): Promise<boolean>;
|
|
24
|
+
size(): Promise<number>;
|
|
25
|
+
private moveToFront;
|
|
26
|
+
private removeNode;
|
|
27
|
+
private evict;
|
|
28
|
+
private evictLRU;
|
|
29
|
+
private evictLFU;
|
|
30
|
+
getStats(): {
|
|
31
|
+
hits: number;
|
|
32
|
+
misses: number;
|
|
33
|
+
size: number;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=l1-memory-store.adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"l1-memory-store.adapter.d.ts","sourceRoot":"","sources":["../../../../src/cache/infrastructure/adapters/l1-memory-store.adapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAC5E,OAAO,EAAE,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 Redis cache store implementation.
|
|
3
|
+
*/
|
|
4
|
+
import { IRedisDriver } from '@nestjs-redisx/core';
|
|
5
|
+
import { ICachePluginOptions, ScanResult, SwrEntry } from '../../../shared/types';
|
|
6
|
+
import { IL2CacheStore } from '../../application/ports/l2-cache-store.port';
|
|
7
|
+
import { Serializer } from '../../domain/services/serializer.service';
|
|
8
|
+
import { CacheEntry } from '../../domain/value-objects/cache-entry.vo';
|
|
9
|
+
export declare class L2RedisStoreAdapter implements IL2CacheStore {
|
|
10
|
+
private readonly driver;
|
|
11
|
+
private readonly options;
|
|
12
|
+
private readonly serializer;
|
|
13
|
+
private readonly keyPrefix;
|
|
14
|
+
private readonly defaultTtl;
|
|
15
|
+
private hits;
|
|
16
|
+
private misses;
|
|
17
|
+
constructor(driver: IRedisDriver, options: ICachePluginOptions, serializer: Serializer);
|
|
18
|
+
get<T>(key: string): Promise<CacheEntry<T> | null>;
|
|
19
|
+
set<T>(key: string, entry: CacheEntry<T>, ttl?: number): Promise<void>;
|
|
20
|
+
delete(key: string): Promise<boolean>;
|
|
21
|
+
clear(): Promise<void>;
|
|
22
|
+
has(key: string): Promise<boolean>;
|
|
23
|
+
ttl(key: string): Promise<number>;
|
|
24
|
+
expire(key: string, ttl: number): Promise<boolean>;
|
|
25
|
+
scan(pattern: string, count?: number): Promise<ScanResult>;
|
|
26
|
+
getMany<T>(keys: string[]): Promise<Array<CacheEntry<T> | null>>;
|
|
27
|
+
setMany<T>(entries: Array<{
|
|
28
|
+
key: string;
|
|
29
|
+
entry: CacheEntry<T>;
|
|
30
|
+
ttl?: number;
|
|
31
|
+
}>): Promise<void>;
|
|
32
|
+
private buildKey;
|
|
33
|
+
private scanKeys;
|
|
34
|
+
getStats(): Promise<{
|
|
35
|
+
hits: number;
|
|
36
|
+
misses: number;
|
|
37
|
+
}>;
|
|
38
|
+
getSwr<T>(key: string): Promise<SwrEntry<T> | null>;
|
|
39
|
+
setSwr<T>(key: string, swrEntry: SwrEntry<T>): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=l2-redis-store.adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"l2-redis-store.adapter.d.ts","sourceRoot":"","sources":["../../../../src/cache/infrastructure/adapters/l2-redis-store.adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAgB,YAAY,EAAa,MAAM,qBAAqB,CAAC;AAI5E,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,2CAA2C,CAAC;AAKvE,qBACa,mBAAoB,YAAW,aAAa;IAO/B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACf,OAAO,CAAC,QAAQ,CAAC,OAAO;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU;IARjD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,MAAM,CAAK;gBAGsB,MAAM,EAAE,YAAY,EACZ,OAAO,EAAE,mBAAmB,EACtC,UAAU,EAAE,UAAU;IAMvD,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAmBlD,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYtE,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAUrC,KAAK,IAAI,OAAO,CAAC,I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ider } from '@nestjs/common';
|
|
6
|
+
import { IRedisXPlugin } from '@nestjs-redisx/core';
|
|
7
|
+
import { ICachePluginOptions } from './shared/types';
|
|
8
|
+
export declare class CachePlugin implements IRedisXPlugin {
|
|
9
|
+
private readonly options;
|
|
10
|
+
readonly name = "cache";
|
|
11
|
+
readonly version = "0.1.0";
|
|
12
|
+
readonly description = "Advanced caching with L1+L2, anti-stampede, SWR, and tag invalidation";
|
|
13
|
+
constructor(options?: ICachePluginOptions);
|
|
14
|
+
getProviders(): Provider[];
|
|
15
|
+
getExports(): Array<string | symbol | Provider>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=cache.plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.plugin.d.ts","sourceRoot":"","sources":["../src/cache.plugin.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAcpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAMrD,qBAAa,WAAY,YAAW,aAAa;IAKnC,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJpC,QAAQ,CAAC,IAAI,WAAW;IACxB,QAAQ,CAAC,OAAO,WAAW;IAC3B,QAAQ,CAAC,WAAW,2EAA2E;gBAElE,OAAO,GAAE,mBAAwB;IAE9D,YAAY,IAAI,QAAQ,EAAE;IAsG1B,UAAU,IAAI,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;CAGhD"}
|