26
27// Initialize the cache table
28export async function initializeCache(): Promise<void> {
29 try {
30 console.log("Initializing cache table...");
50
51// Normalize plant name for consistent caching
52function normalizePlantName(name: string): string {
53 return name.toLowerCase()
54 .trim()
59
60// Get cached plant information
61export async function getCachedPlant(plantName: string): Promise<PlantInfo | null> {
62 const normalizedName = normalizePlantName(plantName);
63 console.log(`getCachedPlant: original="${plantName}", normalized="${normalizedName}"`);
90
91// Cache plant information
92export async function cachePlant(plantName: string, plantInfo: PlantInfo): Promise<void> {
93 const normalizedName = normalizePlantName(plantName);
94 const now = new Date().toISOString();
119
120// Get cache statistics
121export async function getCacheStats(): Promise<{
122 totalEntries: number;
123 oldestEntry: string | null;
154
155// List all cached plants (for debugging/admin purposes)
156export async function listCachedPlants(): Promise<
157 Array<{
158 plantName: string;
178
179// Clear cache (for maintenance)
180export async function clearCache(): Promise<void> {
181 try {
182 await sqlite.execute(`DELETE FROM ${TABLE_NAME}`);