Skip to content

Commit

Permalink
Merge pull request #5 from zeytechinc/bugfix/expose-cachemgr
Browse files Browse the repository at this point in the history
Exposes cache manager interface.
  • Loading branch information
skrenek authored Aug 5, 2024
2 parents 9fd9a45 + 7474f6c commit 693d1b7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zeytech/cache-adonisjs",
"description": "Provides LRU and Timed LRU in-memory cache with support for Adonis 6+",
"version": "2.0.0",
"version": "2.0.1",
"engines": {
"node": ">=20.6.0"
},
Expand Down
3 changes: 2 additions & 1 deletion src/cache_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import { CacheEngineType } from './cache.js'
import { CacheEngine, MemoryCacheEngine, RedisCacheEngine } from './engines/index.js'
import { LRUCache } from './lru_cache.js'
import { TLRUCache } from './tlru_cache.js'
import { CacheManagerContract } from './types.js'

export class CacheManager {
export class CacheManager implements CacheManagerContract {
#caches: Map<string, LRUCache<any> | TLRUCache<any>>

constructor() {
Expand Down
26 changes: 25 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { CacheItem } from './cache.js'
import { CacheEngineType, CacheItem } from './cache.js'
import { LRUCache } from './lru_cache.js'
import { TLRUCache } from './tlru_cache.js'

export interface BaseHealthCheckMetadata {
size: number
Expand Down Expand Up @@ -49,3 +51,25 @@ export interface BaseCache<T> {
getHealthCheckMessage(): Promise<string>
getHealthCheckMeta(includeItems?: boolean, dateFormat?: string): Promise<object>
}
export interface CacheManagerContract {
createLRUCache<T>(
key: string,
maxItems: number,
storage: CacheEngineType,
displayName?: string,
connectionName?: string
): LRUCache<T>
createTLRUCache<T>(
key: string,
maxItems: number,
maxItemAge: number,
storage: CacheEngineType,
displayName?: string,
connectionName?: string
): TLRUCache<T>
getLRUCache<T>(key: string): LRUCache<T> | undefined
getTLRUCache<T>(key: string): TLRUCache<T> | undefined
getKeys(): string[]
removeCache(key: string): Promise<boolean>
shutdown(): Promise<void>
}

0 comments on commit 693d1b7

Please sign in to comment.