@@ -13,7 +13,7 @@ export class CacheService {
1313 private logger : Logger
1414 private cache : Map < string , CacheEntry < any > >
1515
16- constructor ( ) {
16+ constructor ( ) {
1717 this . logger = initLogger ( )
1818 this . cache = new Map ( )
1919 }
@@ -29,7 +29,7 @@ export class CacheService {
2929 ) : Promise < T > {
3030 const { ttlDays = 7 } = options
3131 const now = Date . now ( )
32-
32+
3333 // Check if we have valid cached data
3434 const cached = this . cache . get ( key )
3535 if ( cached && cached . expiresAt > now ) {
@@ -41,19 +41,19 @@ export class CacheService {
4141 this . logger . info ( { msg : `Cache miss for key: ${ key } , fetching fresh data...` } )
4242 try {
4343 const data = await fetcher ( )
44-
44+
4545 // Calculate expiration time
4646 const expiresAt = now + ( ttlDays * 24 * 60 * 60 * 1000 )
47-
47+
4848 // Store in cache
4949 this . cache . set ( key , { data, expiresAt } )
50-
51- this . logger . info ( {
52- msg : `Cached data for key: ${ key } ` ,
50+
51+ this . logger . info ( {
52+ msg : `Cached data for key: ${ key } ` ,
5353 expiresAt : new Date ( expiresAt ) . toISOString ( ) ,
54- ttlDays
54+ ttlDays
5555 } )
56-
56+
5757 return data
5858 } catch ( error ) {
5959 this . logger . error ( { err : error , msg : `Failed to fetch data for key: ${ key } ` } )
@@ -64,22 +64,22 @@ export class CacheService {
6464 /**
6565 * Convenience method for fetching HTTP resources with caching
6666 */
67- async fetchHttpWithCache (
67+ async fetchHttpWithCache (
6868 url : string ,
6969 options : CacheOptions & { responseType ?: 'json' | 'text' } = { }
7070 ) : Promise < any > {
7171 const { responseType = 'json' , ...cacheOptions } = options
72-
72+
7373 return this . fetchWithCache (
7474 url ,
7575 async ( ) => {
7676 this . logger . info ( { msg : `Fetching HTTP resource: ${ url } ` } )
7777 const response = await fetch ( url )
78-
78+
7979 if ( ! response . ok ) {
8080 throw new Error ( `HTTP error! status: ${ response . status } ${ response . statusText } ` )
8181 }
82-
82+
8383 const data = responseType === 'json' ? await response . json ( ) : await response . text ( )
8484 this . logger . info ( { msg : `Successfully fetched HTTP resource: ${ url } ` } )
8585 return data
@@ -91,25 +91,25 @@ export class CacheService {
9191 /**
9292 * Clear a specific cache entry
9393 */
94- clearCache ( key : string ) : void {
94+ clearCache ( key : string ) : void {
9595 this . cache . delete ( key )
9696 this . logger . info ( { msg : `Cleared cache for key: ${ key } ` } )
9797 }
9898
9999 /**
100100 * Clear all expired cache entries
101101 */
102- clearExpiredCache ( ) : void {
102+ clearExpiredCache ( ) : void {
103103 const now = Date . now ( )
104104 let clearedCount = 0
105-
105+
106106 for ( const [ key , entry ] of this . cache . entries ( ) ) {
107107 if ( entry . expiresAt <= now ) {
108108 this . cache . delete ( key )
109109 clearedCount ++
110110 }
111111 }
112-
112+
113113 if ( clearedCount > 0 ) {
114114 this . logger . info ( { msg : `Cleared ${ clearedCount } expired cache entries` } )
115115 }
@@ -118,10 +118,10 @@ export class CacheService {
118118 /**
119119 * Get cache statistics
120120 */
121- getCacheStats ( ) : { size : number ; keys : string [ ] } {
121+ getCacheStats ( ) : { size : number ; keys : string [ ] } {
122122 return {
123123 size : this . cache . size ,
124124 keys : Array . from ( this . cache . keys ( ) )
125125 }
126126 }
127- }
127+ }
0 commit comments