Browse Source

chore: Comment out the unused caching utilities (so they're not mistakenly used).

pull/151/head
Trent Larson 3 days ago
parent
commit
5971f0976a
  1. 194
      src/utils/PlatformServiceMixin.ts

194
src/utils/PlatformServiceMixin.ts

@ -59,14 +59,14 @@ import {
// TYPESCRIPT INTERFACES // TYPESCRIPT INTERFACES
// ================================================= // =================================================
/** // /**
* Cache entry interface for storing data with TTL // * Cache entry interface for storing data with TTL
*/ // */
interface CacheEntry<T> { // interface CacheEntry<T> {
data: T; // data: T;
timestamp: number; // timestamp: number;
ttl: number; // milliseconds // ttl: number; // milliseconds
} // }
/** /**
* Vue component interface that uses the PlatformServiceMixin * Vue component interface that uses the PlatformServiceMixin
@ -79,21 +79,21 @@ interface VueComponentWithMixin {
platformService(): PlatformService; platformService(): PlatformService;
} }
/** // /**
* Global cache store for mixin instances // * Global cache store for mixin instances
* Uses WeakMap to avoid memory leaks when components are destroyed // * Uses WeakMap to avoid memory leaks when components are destroyed
*/ // */
const componentCaches = new WeakMap< // const componentCaches = new WeakMap<
VueComponentWithMixin, // VueComponentWithMixin,
Map<string, CacheEntry<unknown>> // Map<string, CacheEntry<unknown>>
>(); // >();
//
/** // /**
* Cache configuration constants // * Cache configuration constants
*/ // */
const CACHE_DEFAULTS = { // const CACHE_DEFAULTS = {
default: 15000, // 15 seconds default TTL // default: 15000, // 15 seconds default TTL
} as const; // } as const;
const _memoryLogs: string[] = []; const _memoryLogs: string[] = [];
@ -203,8 +203,8 @@ export const PlatformServiceMixin = {
logger.debug( logger.debug(
`[PlatformServiceMixin] ActiveDid updated from ${oldDid} to ${newDid}`, `[PlatformServiceMixin] ActiveDid updated from ${oldDid} to ${newDid}`,
); );
// Clear caches that might be affected by the change // // Clear caches that might be affected by the change
this.$clearAllCaches(); // this.$clearAllCaches();
} }
}, },
@ -256,71 +256,71 @@ export const PlatformServiceMixin = {
return (value as T) || defaultValue; return (value as T) || defaultValue;
}, },
// ================================================= // // =================================================
// CACHING UTILITY METHODS // // CACHING UTILITY METHODS
// ================================================= // // =================================================
/** // /**
* Get or initialize cache for this component instance // * Get or initialize cache for this component instance
*/ // */
_getCache(): Map<string, CacheEntry<unknown>> { // _getCache(): Map<string, CacheEntry<unknown>> {
let cache = componentCaches.get(this as unknown as VueComponentWithMixin); // let cache = componentCaches.get(this as unknown as VueComponentWithMixin);
if (!cache) { // if (!cache) {
cache = new Map(); // cache = new Map();
componentCaches.set(this as unknown as VueComponentWithMixin, cache); // componentCaches.set(this as unknown as VueComponentWithMixin, cache);
} // }
return cache; // return cache;
}, // },
/** // /**
* Check if cache entry is valid (not expired) // * Check if cache entry is valid (not expired)
*/ // */
_isCacheValid(entry: CacheEntry<unknown>): boolean { // _isCacheValid(entry: CacheEntry<unknown>): boolean {
return Date.now() - entry.timestamp < entry.ttl; // return Date.now() - entry.timestamp < entry.ttl;
}, // },
/** // /**
* Get data from cache if valid, otherwise return null // * Get data from cache if valid, otherwise return null
*/ // */
_getCached<T>(key: string): T | null { // _getCached<T>(key: string): T | null {
const cache = this._getCache(); // const cache = this._getCache();
const entry = cache.get(key); // const entry = cache.get(key);
if (entry && this._isCacheValid(entry)) { // if (entry && this._isCacheValid(entry)) {
return entry.data as T; // return entry.data as T;
} // }
cache.delete(key); // Clean up expired entries // cache.delete(key); // Clean up expired entries
return null; // return null;
}, // },
/** // /**
* Store data in cache with TTL // * Store data in cache with TTL
*/ // */
_setCached<T>(key: string, data: T, ttl?: number): T { // _setCached<T>(key: string, data: T, ttl?: number): T {
const cache = this._getCache(); // const cache = this._getCache();
const actualTtl = ttl || CACHE_DEFAULTS.default; // const actualTtl = ttl || CACHE_DEFAULTS.default;
cache.set(key, { // cache.set(key, {
data, // data,
timestamp: Date.now(), // timestamp: Date.now(),
ttl: actualTtl, // ttl: actualTtl,
}); // });
return data; // return data;
}, // },
/** // /**
* Invalidate specific cache entry // * Invalidate specific cache entry
*/ // */
_invalidateCache(key: string): void { // _invalidateCache(key: string): void {
const cache = this._getCache(); // const cache = this._getCache();
cache.delete(key); // cache.delete(key);
}, // },
/** // /**
* Clear all cache entries for this component // * Clear all cache entries for this component
*/ // */
_clearCache(): void { // _clearCache(): void {
const cache = this._getCache(); // const cache = this._getCache();
cache.clear(); // cache.clear();
}, // },
// ================================================= // =================================================
// ENHANCED DATABASE METHODS (with error handling) // ENHANCED DATABASE METHODS (with error handling)
@ -872,13 +872,13 @@ export const PlatformServiceMixin = {
return await this.$contacts(); return await this.$contacts();
}, },
/** // /**
* Clear all caches for this component - $clearAllCaches() // * Clear all caches for this component - $clearAllCaches()
* Useful for manual cache management // * Useful for manual cache management
*/ // */
$clearAllCaches(): void { // $clearAllCaches(): void {
this._clearCache(); // this._clearCache();
}, // },
// ================================================= // =================================================
// HIGH-LEVEL ENTITY OPERATIONS (eliminate verbose SQL patterns) // HIGH-LEVEL ENTITY OPERATIONS (eliminate verbose SQL patterns)

Loading…
Cancel
Save