/**
 * Unified Cache Types
 *
 * This module provides common cache type definitions that can be used
 * throughout the codebase. Instead of each module defining its own
 * CacheEntry/CacheStats, import from here for consistency.
 *
 * Migration guide:
 * - Use BaseCacheEntry<T> for simple key-value caches
 * - Use TimedCacheEntry<T> for TTL-based caches
 * - Use LRUCacheEntry<T> for LRU caches with access tracking
 * - Use BaseCacheStats for basic statistics
 * - Use DetailedCacheStats for comprehensive statistics
 */
// ============================================================================
// Type Guards
// ============================================================================
/**
 * Check if an object is a valid cache entry
 */
export function isCacheEntry(obj) {
    return (typeof obj === 'object' &&
        obj !== null &&
        'value' in obj &&
        'timestamp' in obj &&
        typeof obj.timestamp === 'number');
}
/**
 * Check if a cache entry has expired
 */
export function isExpired(entry) {
    if (!entry.expiresAt)
        return false;
    return Date.now() > entry.expiresAt;
}
/**
 * Calculate cache hit rate
 */
export function calculateHitRate(hits, misses) {
    const total = hits + misses;
    return total > 0 ? hits / total : 0;
}
// ============================================================================
// Factory Functions
// ============================================================================
/**
 * Create a basic cache entry
 */
export function createCacheEntry(value) {
    return {
        value,
        timestamp: Date.now(),
    };
}
/**
 * Create a timed cache entry
 */
export function createTimedCacheEntry(value, ttlMs) {
    const now = Date.now();
    return {
        value,
        timestamp: now,
        expiresAt: now + ttlMs,
        ttl: ttlMs,
    };
}
/**
 * Create an LRU cache entry
 */
export function createLRUCacheEntry(value) {
    const now = Date.now();
    return {
        value,
        timestamp: now,
        createdAt: now,
        accessedAt: now,
        accessCount: 1,
    };
}
/**
 * Create initial cache statistics
 */
export function createCacheStats(maxSize = 0) {
    return {
        size: 0,
        maxSize,
        hits: 0,
        misses: 0,
        evictions: 0,
        hitRate: 0,
    };
}
//# sourceMappingURL=cache-types.js.map