@coastal-programs/notion-cli
Version:
Unofficial Notion CLI optimized for automation and AI agents. Non-interactive interface for Notion API v5.2.1 with intelligent caching, retry logic, structured error handling, and comprehensive testing.
84 lines (83 loc) • 1.96 kB
TypeScript
/**
* Simple in-memory caching layer for Notion API responses
* Supports TTL (time-to-live) and cache invalidation
*/
export interface CacheEntry<T> {
data: T;
timestamp: number;
ttl: number;
}
export interface CacheStats {
hits: number;
misses: number;
sets: number;
evictions: number;
size: number;
}
export interface CacheConfig {
enabled: boolean;
defaultTtl: number;
maxSize: number;
ttlByType: {
dataSource: number;
database: number;
user: number;
page: number;
block: number;
};
}
export declare class CacheManager {
private cache;
private stats;
private config;
constructor(config?: Partial<CacheConfig>);
/**
* Generate a cache key from resource type and identifiers
*/
private generateKey;
/**
* Check if a cache entry is still valid
*/
private isValid;
/**
* Evict expired entries
*/
private evictExpired;
/**
* Evict oldest entries if cache is full
*/
private evictOldest;
/**
* Get a value from cache
*/
get<T>(type: string, ...identifiers: Array<string | number | object>): T | null;
/**
* Set a value in cache with optional custom TTL
*/
set<T>(type: string, data: T, customTtl?: number, ...identifiers: Array<string | number | object>): void;
/**
* Invalidate specific cache entries by type and optional identifiers
*/
invalidate(type: string, ...identifiers: Array<string | number | object>): void;
/**
* Clear all cache entries
*/
clear(): void;
/**
* Get cache statistics
*/
getStats(): CacheStats;
/**
* Get cache hit rate
*/
getHitRate(): number;
/**
* Check if cache is enabled
*/
isEnabled(): boolean;
/**
* Get current configuration
*/
getConfig(): CacheConfig;
}
export declare const cacheManager: CacheManager;