[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6JB19KYE3QJKY71EN4E6QY5":3,"skill-same:01M6JB19KYE3QJKY71EN4E6QY5":70},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":38,"linkOnly":39,"markdownContent":40,"markdownBody":41,"frontMatter":42,"refName":43,"commitSha":44,"skillDirectory":45,"forksCount":13,"repositoryHtmlUrl":46,"repositoryHomepageUrl":6,"ownerHtmlUrl":47,"ownerBlogUrl":6,"ownerDescription":48,"updatedAt":49,"install":50,"resources":63},"01M6JB19KYE3QJKY71EN4E6QY5","delon-cache-caching-strategies",null,"Implement caching strategies using @delon\u002Fcache. Use this skill when adding memory cache, LocalStorage cache, SessionStorage cache, or cache interceptors for HTTP requests. Supports TTL-based expiration, cache invalidation, cache grouping, and persistent storage. Optimizes performance by reducing redundant API calls and database queries.","superhealth\u002Fskills-hub","superhealth","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F6292112?v=4","01M6JA6E7F21BYK5W3E4P270TT","01M6JA6EC0W8MPHKDJVBZDSEZ0",0,"MIT","https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub\u002Fblob\u002Fmaster\u002Fskills\u002F7spade\u002Fdelon-cache-caching-strategies\u002FSKILL.md",[],[18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37],"cache","delon cache caching strategies","caching strategies","caching","strategies","for","memory","interceptors","requests","ttl","calls","database queries","grouping","queries","use","api","database","http","implement","performance","2026-11-10 10:12:30",false,"---\nname: delon-cache-caching-strategies\ndescription: \"Implement caching strategies using @delon\u002Fcache. Use this skill when adding memory cache, LocalStorage cache, SessionStorage cache, or cache interceptors for HTTP requests. Supports TTL-based expiration, cache invalidation, cache grouping, and persistent storage. Optimizes performance by reducing redundant API calls and database queries.\"\nlicense: \"MIT\"\n---\n\n# @delon\u002Fcache Caching Strategies Skill\n\nThis skill helps implement caching using @delon\u002Fcache library.\n\n## Core Principles\n\n### Cache Types\n- **Memory Cache**: Fast, in-memory caching (lost on page refresh)\n- **LocalStorage Cache**: Persistent across sessions\n- **SessionStorage Cache**: Persistent within session only\n\n### Features\n- TTL-based expiration\n- Cache invalidation (manual and automatic)\n- Cache grouping and namespacing\n- HTTP request caching with interceptors\n- Observable support for async data\n\n## Configuration\n\n```typescript\n\u002F\u002F src\u002Fapp\u002Fapp.config.ts\nimport { ApplicationConfig } from '@angular\u002Fcore';\nimport { provideDelonCache } from '@delon\u002Fcache';\n\nexport const appConfig: ApplicationConfig = {\n  providers: [\n    provideDelonCache({\n      mode: 'promise',  \u002F\u002F 'promise' | 'none'\n      request_method: 'POST',\n      meta_key: '__cache_meta',\n      prefix: '',\n      expire: 3600000  \u002F\u002F Default TTL: 1 hour (ms)\n    })\n  ]\n};\n```\n\n## Cache Service\n\n```typescript\n\u002F\u002F src\u002Fapp\u002Fcore\u002Fservices\u002Fcache.service.ts\nimport { Injectable, inject } from '@angular\u002Fcore';\nimport { CacheService as DelonCacheService } from '@delon\u002Fcache';\nimport { Observable } from 'rxjs';\n\n@Injectable({ providedIn: 'root' })\nexport class CacheService {\n  private cache = inject(DelonCacheService);\n  \n  \u002F**\n   * Set cache with key\n   *\u002F\n  set\u003CT>(key: string, value: T, options?: { \n    type?: 'memory' | 'localStorage' | 'sessionStorage';\n    expire?: number; \u002F\u002F TTL in milliseconds\n  }): void {\n    this.cache.set(key, value, {\n      type: options?.type || 'memory',\n      expire: options?.expire || 3600000 \u002F\u002F 1 hour default\n    });\n  }\n  \n  \u002F**\n   * Get cache by key\n   *\u002F\n  get\u003CT>(key: string): T | null {\n    return this.cache.get\u003CT>(key);\n  }\n  \n  \u002F**\n   * Check if cache exists and is not expired\n   *\u002F\n  has(key: string): boolean {\n    return this.cache.has(key);\n  }\n  \n  \u002F**\n   * Remove cache by key\n   *\u002F\n  remove(key: string): void {\n    this.cache.remove(key);\n  }\n  \n  \u002F**\n   * Clear all cache\n   *\u002F\n  clear(): void {\n    this.cache.clear();\n  }\n  \n  \u002F**\n   * Get or set cache (lazy loading pattern)\n   *\u002F\n  getOrSet\u003CT>(\n    key: string, \n    factory: () => Observable\u003CT> | Promise\u003CT>,\n    options?: {\n      type?: 'memory' | 'localStorage' | 'sessionStorage';\n      expire?: number;\n    }\n  ): Observable\u003CT> {\n    if (this.has(key)) {\n      return new Observable(observer => {\n        observer.next(this.get\u003CT>(key)!);\n        observer.complete();\n      });\n    }\n    \n    const result = factory();\n    \n    if (result instanceof Observable) {\n      return new Observable(observer => {\n        result.subscribe({\n          next: (value) => {\n            this.set(key, value, options);\n            observer.next(value);\n          },\n          error: (err) => observer.error(err),\n          complete: () => observer.complete()\n        });\n      });\n    }\n    \n    return new Observable(observer => {\n      result.then(value => {\n        this.set(key, value, options);\n        observer.next(value);\n        observer.complete();\n      }).catch(err => observer.error(err));\n    });\n  }\n}\n```\n\n## Memory Cache (Default)\n\n```typescript\nimport { Component, inject, signal } from '@angular\u002Fcore';\nimport { CacheService } from '@core\u002Fservices\u002Fcache.service';\n\n@Component({\n  selector: 'app-task-list',\n  template: `\n    \u003Cbutton nz-button (click)=\"loadTasks()\">Load Tasks\u003C\u002Fbutton>\n    \u003Cbutton nz-button (click)=\"clearCache()\">Clear Cache\u003C\u002Fbutton>\n    \n    @if (loading()) {\n      \u003Cnz-spin \u002F>\n    } @else {\n      @for (task of tasks(); track task.id) {\n        \u003Cdiv>{{ task.title }}\u003C\u002Fdiv>\n      }\n    }\n  `\n})\nexport class TaskListComponent {\n  private cacheService = inject(CacheService);\n  private taskService = inject(TaskService);\n  \n  loading = signal(false);\n  tasks = signal\u003CTask[]>([]);\n  \n  private readonly CACHE_KEY = 'tasks:list';\n  \n  async loadTasks(): Promise\u003Cvoid> {\n    \u002F\u002F Try to get from cache first\n    const cached = this.cacheService.get\u003CTask[]>(this.CACHE_KEY);\n    \n    if (cached) {\n      console.log('Loading from cache');\n      this.tasks.set(cached);\n      return;\n    }\n    \n    \u002F\u002F Load from API\n    this.loading.set(true);\n    try {\n      const tasks = await this.taskService.getTasks();\n      \n      \u002F\u002F Cache for 5 minutes\n      this.cacheService.set(this.CACHE_KEY, tasks, {\n        type: 'memory',\n        expire: 5 * 60 * 1000 \u002F\u002F 5 minutes\n      });\n      \n      this.tasks.set(tasks);\n    } finally {\n      this.loading.set(false);\n    }\n  }\n  \n  clearCache(): void {\n    this.cacheService.remove(this.CACHE_KEY);\n    console.log('Cache cleared');\n  }\n}\n```\n\n## LocalStorage Cache (Persistent)\n\n```typescript\nimport { Injectable, inject } from '@angular\u002Fcore';\nimport { CacheService } from '@core\u002Fservices\u002Fcache.service';\n\n@Injectable({ providedIn: 'root' })\nexport class UserPreferencesService {\n  private cacheService = inject(CacheService);\n  \n  private readonly CACHE_KEY = 'user:preferences';\n  \n  \u002F**\n   * Save user preferences (persists across sessions)\n   *\u002F\n  savePreferences(preferences: UserPreferences): void {\n    this.cacheService.set(this.CACHE_KEY, preferences, {\n      type: 'localStorage',\n      expire: 30 * 24 * 60 * 60 * 1000 \u002F\u002F 30 days\n    });\n  }\n  \n  \u002F**\n   * Load user preferences\n   *\u002F\n  loadPreferences(): UserPreferences | null {\n    return this.cacheService.get\u003CUserPreferences>(this.CACHE_KEY);\n  }\n  \n  \u002F**\n   * Clear preferences\n   *\u002F\n  clearPreferences(): void {\n    this.cacheService.remove(this.CACHE_KEY);\n  }\n}\n\ninterface UserPreferences {\n  theme: 'light' | 'dark';\n  language: string;\n  sidebarCollapsed: boolean;\n}\n```\n\n## SessionStorage Cache\n\n```typescript\n\u002F**\n * Cache search results for current session only\n *\u002F\n@Injectable({ providedIn: 'root' })\nexport class SearchService {\n  private cacheService = inject(CacheService);\n  \n  async search(query: string): Promise\u003CSearchResult[]> {\n    const cacheKey = `search:${query}`;\n    \n    \u002F\u002F Check session cache\n    const cached = this.cacheService.get\u003CSearchResult[]>(cacheKey);\n    if (cached) {\n      return cached;\n    }\n    \n    \u002F\u002F Perform search\n    const results = await this.performSearch(query);\n    \n    \u002F\u002F Cache for current session only\n    this.cacheService.set(cacheKey, results, {\n      type: 'sessionStorage',\n      expire: 30 * 60 * 1000 \u002F\u002F 30 minutes\n    });\n    \n    return results;\n  }\n  \n  private async performSearch(query: string): Promise\u003CSearchResult[]> {\n    \u002F\u002F API call\n    return [];\n  }\n}\n```\n\n## Lazy Loading with getOrSet\n\n```typescript\n@Injectable({ providedIn: 'root' })\nexport class ConfigService {\n  private cacheService = inject(CacheService);\n  private http = inject(HttpClient);\n  \n  \u002F**\n   * Load configuration with automatic caching\n   *\u002F\n  loadConfig(): Observable\u003CAppConfig> {\n    return this.cacheService.getOrSet(\n      'app:config',\n      () => this.http.get\u003CAppConfig>('\u002Fapi\u002Fconfig'),\n      {\n        type: 'localStorage',\n        expire: 24 * 60 * 60 * 1000 \u002F\u002F 24 hours\n      }\n    );\n  }\n}\n```\n\n## Cache Invalidation\n\n### Manual Invalidation\n\n```typescript\n@Injectable({ providedIn: 'root' })\nexport class TaskService {\n  private cacheService = inject(CacheService);\n  private taskRepository = inject(TaskRepository);\n  \n  \u002F**\n   * Create task and invalidate cache\n   *\u002F\n  async createTask(task: Omit\u003CTask, 'id'>): Promise\u003CTask> {\n    const created = await this.taskRepository.create(task);\n    \n    \u002F\u002F Invalidate task list cache\n    this.cacheService.remove('tasks:list');\n    this.cacheService.remove(`tasks:blueprint:${task.blueprintId}`);\n    \n    return created;\n  }\n  \n  \u002F**\n   * Update task and invalidate cache\n   *\u002F\n  async updateTask(id: string, updates: Partial\u003CTask>): Promise\u003CTask> {\n    const updated = await this.taskRepository.update(id, updates);\n    \n    \u002F\u002F Invalidate specific task cache\n    this.cacheService.remove(`tasks:${id}`);\n    \n    \u002F\u002F Invalidate list caches\n    this.cacheService.remove('tasks:list');\n    \n    return updated;\n  }\n}\n```\n\n### Group Cache Invalidation\n\n```typescript\n@Injectable({ providedIn: 'root' })\nexport class CacheInvalidationService {\n  private cacheService = inject(CacheService);\n  \n  \u002F**\n   * Invalidate all caches with prefix\n   *\u002F\n  invalidateGroup(prefix: string): void {\n    \u002F\u002F @delon\u002Fcache doesn't have built-in group invalidation\n    \u002F\u002F So we track cache keys manually\n    const keys = this.getCacheKeys(prefix);\n    keys.forEach(key => this.cacheService.remove(key));\n  }\n  \n  private cacheKeys = new Set\u003Cstring>();\n  \n  registerCacheKey(key: string): void {\n    this.cacheKeys.add(key);\n  }\n  \n  private getCacheKeys(prefix: string): string[] {\n    return Array.from(this.cacheKeys).filter(key => key.startsWith(prefix));\n  }\n}\n```\n\n## HTTP Cache Interceptor\n\n```typescript\n\u002F\u002F src\u002Fapp\u002Fcore\u002Finterceptors\u002Fcache.interceptor.ts\nimport { HttpInterceptorFn, HttpResponse } from '@angular\u002Fcommon\u002Fhttp';\nimport { inject } from '@angular\u002Fcore';\nimport { CacheService } from '@core\u002Fservices\u002Fcache.service';\nimport { of, tap } from 'rxjs';\n\n\u002F**\n * Cache GET requests\n *\u002F\nexport const cacheInterceptor: HttpInterceptorFn = (req, next) => {\n  const cacheService = inject(CacheService);\n  \n  \u002F\u002F Only cache GET requests\n  if (req.method !== 'GET') {\n    return next(req);\n  }\n  \n  \u002F\u002F Skip cache for certain URLs\n  const skipCache = req.headers.has('X-Skip-Cache') || \n                    req.url.includes('\u002Fapi\u002Frealtime');\n  \n  if (skipCache) {\n    return next(req);\n  }\n  \n  \u002F\u002F Generate cache key from URL + params\n  const cacheKey = `http:${req.urlWithParams}`;\n  \n  \u002F\u002F Check cache\n  const cached = cacheService.get\u003CHttpResponse\u003Cany>>(cacheKey);\n  if (cached) {\n    console.log('Serving from cache:', cacheKey);\n    return of(cached);\n  }\n  \n  \u002F\u002F Make request and cache response\n  return next(req).pipe(\n    tap(event => {\n      if (event instanceof HttpResponse) {\n        cacheService.set(cacheKey, event, {\n          type: 'memory',\n          expire: 5 * 60 * 1000 \u002F\u002F 5 minutes\n        });\n      }\n    })\n  );\n};\n```\n\n### Register Interceptor\n\n```typescript\n\u002F\u002F src\u002Fapp\u002Fapp.config.ts\nimport { provideHttpClient, withInterceptors } from '@angular\u002Fcommon\u002Fhttp';\nimport { cacheInterceptor } from '@core\u002Finterceptors\u002Fcache.interceptor';\n\nexport const appConfig: ApplicationConfig = {\n  providers: [\n    provideHttpClient(\n      withInterceptors([cacheInterceptor])\n    )\n  ]\n};\n```\n\n## Cache Namespacing\n\n```typescript\n@Injectable({ providedIn: 'root' })\nexport class NamespacedCacheService {\n  private cacheService = inject(CacheService);\n  \n  constructor(private namespace: string) {}\n  \n  private getKey(key: string): string {\n    return `${this.namespace}:${key}`;\n  }\n  \n  set\u003CT>(key: string, value: T, options?: any): void {\n    this.cacheService.set(this.getKey(key), value, options);\n  }\n  \n  get\u003CT>(key: string): T | null {\n    return this.cacheService.get\u003CT>(this.getKey(key));\n  }\n  \n  remove(key: string): void {\n    this.cacheService.remove(this.getKey(key));\n  }\n}\n\n\u002F\u002F Usage\n@Injectable({ providedIn: 'root' })\nexport class TaskCacheService extends NamespacedCacheService {\n  constructor() {\n    super('tasks');\n  }\n}\n```\n\n## Cache Patterns\n\n### Read-Through Cache\n\n```typescript\nasync getTask(id: string): Promise\u003CTask> {\n  const cacheKey = `tasks:${id}`;\n  \n  \u002F\u002F Try cache\n  let task = this.cacheService.get\u003CTask>(cacheKey);\n  if (task) {\n    return task;\n  }\n  \n  \u002F\u002F Load from repository\n  task = await this.taskRepository.findById(id);\n  \n  \u002F\u002F Cache result\n  if (task) {\n    this.cacheService.set(cacheKey, task, {\n      type: 'memory',\n      expire: 10 * 60 * 1000 \u002F\u002F 10 minutes\n    });\n  }\n  \n  return task;\n}\n```\n\n### Write-Through Cache\n\n```typescript\nasync updateTask(id: string, updates: Partial\u003CTask>): Promise\u003CTask> {\n  \u002F\u002F Update in repository\n  const updated = await this.taskRepository.update(id, updates);\n  \n  \u002F\u002F Update cache\n  const cacheKey = `tasks:${id}`;\n  this.cacheService.set(cacheKey, updated, {\n    type: 'memory',\n    expire: 10 * 60 * 1000\n  });\n  \n  return updated;\n}\n```\n\n### Cache-Aside Pattern\n\n```typescript\nasync getTasks(blueprintId: string): Promise\u003CTask[]> {\n  const cacheKey = `tasks:blueprint:${blueprintId}`;\n  \n  \u002F\u002F Check cache\n  if (this.cacheService.has(cacheKey)) {\n    return this.cacheService.get\u003CTask[]>(cacheKey)!;\n  }\n  \n  \u002F\u002F Load from repository\n  const tasks = await this.taskRepository.findByBlueprintId(blueprintId);\n  \n  \u002F\u002F Populate cache\n  this.cacheService.set(cacheKey, tasks, {\n    type: 'memory',\n    expire: 5 * 60 * 1000\n  });\n  \n  return tasks;\n}\n```\n\n## Best Practices\n\n### Cache Key Naming\n\n```typescript\n\u002F\u002F Good: Descriptive, hierarchical keys\n'users:123'\n'tasks:blueprint:abc-123'\n'config:app:theme'\n\n\u002F\u002F Bad: Generic, flat keys\n'user'\n'data123'\n'cache'\n```\n\n### TTL Guidelines\n\n```typescript\n\u002F\u002F Static data: 1 hour - 1 day\nthis.cacheService.set('config', data, { expire: 24 * 60 * 60 * 1000 });\n\n\u002F\u002F Dynamic data: 1-10 minutes\nthis.cacheService.set('tasks', data, { expire: 5 * 60 * 1000 });\n\n\u002F\u002F User-specific: Session duration\nthis.cacheService.set('user:prefs', data, { type: 'sessionStorage' });\n\n\u002F\u002F Persistent: 30 days\nthis.cacheService.set('settings', data, { \n  type: 'localStorage',\n  expire: 30 * 24 * 60 * 60 * 1000 \n});\n```\n\n## Checklist\n\nWhen implementing caching:\n\n- [ ] Choose appropriate cache type (memory\u002FlocalStorage\u002FsessionStorage)\n- [ ] Set reasonable TTL values\n- [ ] Implement cache invalidation on data changes\n- [ ] Use descriptive, hierarchical cache keys\n- [ ] Handle cache misses gracefully\n- [ ] Monitor cache hit\u002Fmiss rates\n- [ ] Consider cache size limits\n- [ ] Test cache expiration\n- [ ] Document caching strategy\n- [ ] Implement cache warming for critical data\n\n## References\n\n- [@delon\u002Fcache Documentation](https:\u002F\u002Fng-alain.com\u002Fcache)\n- [Caching Best Practices](https:\u002F\u002Faws.amazon.com\u002Fcaching\u002Fbest-practices\u002F)\n- [Cache Patterns](https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Fazure\u002Farchitecture\u002Fpatterns\u002Fcache-aside)\n","# @delon\u002Fcache Caching Strategies Skill\n\nThis skill helps implement caching using @delon\u002Fcache library.\n\n## Core Principles\n\n### Cache Types\n- **Memory Cache**: Fast, in-memory caching (lost on page refresh)\n- **LocalStorage Cache**: Persistent across sessions\n- **SessionStorage Cache**: Persistent within session only\n\n### Features\n- TTL-based expiration\n- Cache invalidation (manual and automatic)\n- Cache grouping and namespacing\n- HTTP request caching with interceptors\n- Observable support for async data\n\n## Configuration\n\n```typescript\n\u002F\u002F src\u002Fapp\u002Fapp.config.ts\nimport { ApplicationConfig } from '@angular\u002Fcore';\nimport { provideDelonCache } from '@delon\u002Fcache';\n\nexport const appConfig: ApplicationConfig = {\n  providers: [\n    provideDelonCache({\n      mode: 'promise',  \u002F\u002F 'promise' | 'none'\n      request_method: 'POST',\n      meta_key: '__cache_meta',\n      prefix: '',\n      expire: 3600000  \u002F\u002F Default TTL: 1 hour (ms)\n    })\n  ]\n};\n```\n\n## Cache Service\n\n```typescript\n\u002F\u002F src\u002Fapp\u002Fcore\u002Fservices\u002Fcache.service.ts\nimport { Injectable, inject } from '@angular\u002Fcore';\nimport { CacheService as DelonCacheService } from '@delon\u002Fcache';\nimport { Observable } from 'rxjs';\n\n@Injectable({ providedIn: 'root' })\nexport class CacheService {\n  private cache = inject(DelonCacheService);\n  \n  \u002F**\n   * Set cache with key\n   *\u002F\n  set\u003CT>(key: string, value: T, options?: { \n    type?: 'memory' | 'localStorage' | 'sessionStorage';\n    expire?: number; \u002F\u002F TTL in milliseconds\n  }): void {\n    this.cache.set(key, value, {\n      type: options?.type || 'memory',\n      expire: options?.expire || 3600000 \u002F\u002F 1 hour default\n    });\n  }\n  \n  \u002F**\n   * Get cache by key\n   *\u002F\n  get\u003CT>(key: string): T | null {\n    return this.cache.get\u003CT>(key);\n  }\n  \n  \u002F**\n   * Check if cache exists and is not expired\n   *\u002F\n  has(key: string): boolean {\n    return this.cache.has(key);\n  }\n  \n  \u002F**\n   * Remove cache by key\n   *\u002F\n  remove(key: string): void {\n    this.cache.remove(key);\n  }\n  \n  \u002F**\n   * Clear all cache\n   *\u002F\n  clear(): void {\n    this.cache.clear();\n  }\n  \n  \u002F**\n   * Get or set cache (lazy loading pattern)\n   *\u002F\n  getOrSet\u003CT>(\n    key: string, \n    factory: () => Observable\u003CT> | Promise\u003CT>,\n    options?: {\n      type?: 'memory' | 'localStorage' | 'sessionStorage';\n      expire?: number;\n    }\n  ): Observable\u003CT> {\n    if (this.has(key)) {\n      return new Observable(observer => {\n        observer.next(this.get\u003CT>(key)!);\n        observer.complete();\n      });\n    }\n    \n    const result = factory();\n    \n    if (result instanceof Observable) {\n      return new Observable(observer => {\n        result.subscribe({\n          next: (value) => {\n            this.set(key, value, options);\n            observer.next(value);\n          },\n          error: (err) => observer.error(err),\n          complete: () => observer.complete()\n        });\n      });\n    }\n    \n    return new Observable(observer => {\n      result.then(value => {\n        this.set(key, value, options);\n        observer.next(value);\n        observer.complete();\n      }).catch(err => observer.error(err));\n    });\n  }\n}\n```\n\n## Memory Cache (Default)\n\n```typescript\nimport { Component, inject, signal } from '@angular\u002Fcore';\nimport { CacheService } from '@core\u002Fservices\u002Fcache.service';\n\n@Component({\n  selector: 'app-task-list',\n  template: `\n    \u003Cbutton nz-button (click)=\"loadTasks()\">Load Tasks\u003C\u002Fbutton>\n    \u003Cbutton nz-button (click)=\"clearCache()\">Clear Cache\u003C\u002Fbutton>\n    \n    @if (loading()) {\n      \u003Cnz-spin \u002F>\n    } @else {\n      @for (task of tasks(); track task.id) {\n        \u003Cdiv>{{ task.title }}\u003C\u002Fdiv>\n      }\n    }\n  `\n})\nexport class TaskListComponent {\n  private cacheService = inject(CacheService);\n  private taskService = inject(TaskService);\n  \n  loading = signal(false);\n  tasks = signal\u003CTask[]>([]);\n  \n  private readonly CACHE_KEY = 'tasks:list';\n  \n  async loadTasks(): Promise\u003Cvoid> {\n    \u002F\u002F Try to get from cache first\n    const cached = this.cacheService.get\u003CTask[]>(this.CACHE_KEY);\n    \n    if (cached) {\n      console.log('Loading from cache');\n      this.tasks.set(cached);\n      return;\n    }\n    \n    \u002F\u002F Load from API\n    this.loading.set(true);\n    try {\n      const tasks = await this.taskService.getTasks();\n      \n      \u002F\u002F Cache for 5 minutes\n      this.cacheService.set(this.CACHE_KEY, tasks, {\n        type: 'memory',\n        expire: 5 * 60 * 1000 \u002F\u002F 5 minutes\n      });\n      \n      this.tasks.set(tasks);\n    } finally {\n      this.loading.set(false);\n    }\n  }\n  \n  clearCache(): void {\n    this.cacheService.remove(this.CACHE_KEY);\n    console.log('Cache cleared');\n  }\n}\n```\n\n## LocalStorage Cache (Persistent)\n\n```typescript\nimport { Injectable, inject } from '@angular\u002Fcore';\nimport { CacheService } from '@core\u002Fservices\u002Fcache.service';\n\n@Injectable({ providedIn: 'root' })\nexport class UserPreferencesService {\n  private cacheService = inject(CacheService);\n  \n  private readonly CACHE_KEY = 'user:preferences';\n  \n  \u002F**\n   * Save user preferences (persists across sessions)\n   *\u002F\n  savePreferences(preferences: UserPreferences): void {\n    this.cacheService.set(this.CACHE_KEY, preferences, {\n      type: 'localStorage',\n      expire: 30 * 24 * 60 * 60 * 1000 \u002F\u002F 30 days\n    });\n  }\n  \n  \u002F**\n   * Load user preferences\n   *\u002F\n  loadPreferences(): UserPreferences | null {\n    return this.cacheService.get\u003CUserPreferences>(this.CACHE_KEY);\n  }\n  \n  \u002F**\n   * Clear preferences\n   *\u002F\n  clearPreferences(): void {\n    this.cacheService.remove(this.CACHE_KEY);\n  }\n}\n\ninterface UserPreferences {\n  theme: 'light' | 'dark';\n  language: string;\n  sidebarCollapsed: boolean;\n}\n```\n\n## SessionStorage Cache\n\n```typescript\n\u002F**\n * Cache search results for current session only\n *\u002F\n@Injectable({ providedIn: 'root' })\nexport class SearchService {\n  private cacheService = inject(CacheService);\n  \n  async search(query: string): Promise\u003CSearchResult[]> {\n    const cacheKey = `search:${query}`;\n    \n    \u002F\u002F Check session cache\n    const cached = this.cacheService.get\u003CSearchResult[]>(cacheKey);\n    if (cached) {\n      return cached;\n    }\n    \n    \u002F\u002F Perform search\n    const results = await this.performSearch(query);\n    \n    \u002F\u002F Cache for current session only\n    this.cacheService.set(cacheKey, results, {\n      type: 'sessionStorage',\n      expire: 30 * 60 * 1000 \u002F\u002F 30 minutes\n    });\n    \n    return results;\n  }\n  \n  private async performSearch(query: string): Promise\u003CSearchResult[]> {\n    \u002F\u002F API call\n    return [];\n  }\n}\n```\n\n## Lazy Loading with getOrSet\n\n```typescript\n@Injectable({ providedIn: 'root' })\nexport class ConfigService {\n  private cacheService = inject(CacheService);\n  private http = inject(HttpClient);\n  \n  \u002F**\n   * Load configuration with automatic caching\n   *\u002F\n  loadConfig(): Observable\u003CAppConfig> {\n    return this.cacheService.getOrSet(\n      'app:config',\n      () => this.http.get\u003CAppConfig>('\u002Fapi\u002Fconfig'),\n      {\n        type: 'localStorage',\n        expire: 24 * 60 * 60 * 1000 \u002F\u002F 24 hours\n      }\n    );\n  }\n}\n```\n\n## Cache Invalidation\n\n### Manual Invalidation\n\n```typescript\n@Injectable({ providedIn: 'root' })\nexport class TaskService {\n  private cacheService = inject(CacheService);\n  private taskRepository = inject(TaskRepository);\n  \n  \u002F**\n   * Create task and invalidate cache\n   *\u002F\n  async createTask(task: Omit\u003CTask, 'id'>): Promise\u003CTask> {\n    const created = await this.taskRepository.create(task);\n    \n    \u002F\u002F Invalidate task list cache\n    this.cacheService.remove('tasks:list');\n    this.cacheService.remove(`tasks:blueprint:${task.blueprintId}`);\n    \n    return created;\n  }\n  \n  \u002F**\n   * Update task and invalidate cache\n   *\u002F\n  async updateTask(id: string, updates: Partial\u003CTask>): Promise\u003CTask> {\n    const updated = await this.taskRepository.update(id, updates);\n    \n    \u002F\u002F Invalidate specific task cache\n    this.cacheService.remove(`tasks:${id}`);\n    \n    \u002F\u002F Invalidate list caches\n    this.cacheService.remove('tasks:list');\n    \n    return updated;\n  }\n}\n```\n\n### Group Cache Invalidation\n\n```typescript\n@Injectable({ providedIn: 'root' })\nexport class CacheInvalidationService {\n  private cacheService = inject(CacheService);\n  \n  \u002F**\n   * Invalidate all caches with prefix\n   *\u002F\n  invalidateGroup(prefix: string): void {\n    \u002F\u002F @delon\u002Fcache doesn't have built-in group invalidation\n    \u002F\u002F So we track cache keys manually\n    const keys = this.getCacheKeys(prefix);\n    keys.forEach(key => this.cacheService.remove(key));\n  }\n  \n  private cacheKeys = new Set\u003Cstring>();\n  \n  registerCacheKey(key: string): void {\n    this.cacheKeys.add(key);\n  }\n  \n  private getCacheKeys(prefix: string): string[] {\n    return Array.from(this.cacheKeys).filter(key => key.startsWith(prefix));\n  }\n}\n```\n\n## HTTP Cache Interceptor\n\n```typescript\n\u002F\u002F src\u002Fapp\u002Fcore\u002Finterceptors\u002Fcache.interceptor.ts\nimport { HttpInterceptorFn, HttpResponse } from '@angular\u002Fcommon\u002Fhttp';\nimport { inject } from '@angular\u002Fcore';\nimport { CacheService } from '@core\u002Fservices\u002Fcache.service';\nimport { of, tap } from 'rxjs';\n\n\u002F**\n * Cache GET requests\n *\u002F\nexport const cacheInterceptor: HttpInterceptorFn = (req, next) => {\n  const cacheService = inject(CacheService);\n  \n  \u002F\u002F Only cache GET requests\n  if (req.method !== 'GET') {\n    return next(req);\n  }\n  \n  \u002F\u002F Skip cache for certain URLs\n  const skipCache = req.headers.has('X-Skip-Cache') || \n                    req.url.includes('\u002Fapi\u002Frealtime');\n  \n  if (skipCache) {\n    return next(req);\n  }\n  \n  \u002F\u002F Generate cache key from URL + params\n  const cacheKey = `http:${req.urlWithParams}`;\n  \n  \u002F\u002F Check cache\n  const cached = cacheService.get\u003CHttpResponse\u003Cany>>(cacheKey);\n  if (cached) {\n    console.log('Serving from cache:', cacheKey);\n    return of(cached);\n  }\n  \n  \u002F\u002F Make request and cache response\n  return next(req).pipe(\n    tap(event => {\n      if (event instanceof HttpResponse) {\n        cacheService.set(cacheKey, event, {\n          type: 'memory',\n          expire: 5 * 60 * 1000 \u002F\u002F 5 minutes\n        });\n      }\n    })\n  );\n};\n```\n\n### Register Interceptor\n\n```typescript\n\u002F\u002F src\u002Fapp\u002Fapp.config.ts\nimport { provideHttpClient, withInterceptors } from '@angular\u002Fcommon\u002Fhttp';\nimport { cacheInterceptor } from '@core\u002Finterceptors\u002Fcache.interceptor';\n\nexport const appConfig: ApplicationConfig = {\n  providers: [\n    provideHttpClient(\n      withInterceptors([cacheInterceptor])\n    )\n  ]\n};\n```\n\n## Cache Namespacing\n\n```typescript\n@Injectable({ providedIn: 'root' })\nexport class NamespacedCacheService {\n  private cacheService = inject(CacheService);\n  \n  constructor(private namespace: string) {}\n  \n  private getKey(key: string): string {\n    return `${this.namespace}:${key}`;\n  }\n  \n  set\u003CT>(key: string, value: T, options?: any): void {\n    this.cacheService.set(this.getKey(key), value, options);\n  }\n  \n  get\u003CT>(key: string): T | null {\n    return this.cacheService.get\u003CT>(this.getKey(key));\n  }\n  \n  remove(key: string): void {\n    this.cacheService.remove(this.getKey(key));\n  }\n}\n\n\u002F\u002F Usage\n@Injectable({ providedIn: 'root' })\nexport class TaskCacheService extends NamespacedCacheService {\n  constructor() {\n    super('tasks');\n  }\n}\n```\n\n## Cache Patterns\n\n### Read-Through Cache\n\n```typescript\nasync getTask(id: string): Promise\u003CTask> {\n  const cacheKey = `tasks:${id}`;\n  \n  \u002F\u002F Try cache\n  let task = this.cacheService.get\u003CTask>(cacheKey);\n  if (task) {\n    return task;\n  }\n  \n  \u002F\u002F Load from repository\n  task = await this.taskRepository.findById(id);\n  \n  \u002F\u002F Cache result\n  if (task) {\n    this.cacheService.set(cacheKey, task, {\n      type: 'memory',\n      expire: 10 * 60 * 1000 \u002F\u002F 10 minutes\n    });\n  }\n  \n  return task;\n}\n```\n\n### Write-Through Cache\n\n```typescript\nasync updateTask(id: string, updates: Partial\u003CTask>): Promise\u003CTask> {\n  \u002F\u002F Update in repository\n  const updated = await this.taskRepository.update(id, updates);\n  \n  \u002F\u002F Update cache\n  const cacheKey = `tasks:${id}`;\n  this.cacheService.set(cacheKey, updated, {\n    type: 'memory',\n    expire: 10 * 60 * 1000\n  });\n  \n  return updated;\n}\n```\n\n### Cache-Aside Pattern\n\n```typescript\nasync getTasks(blueprintId: string): Promise\u003CTask[]> {\n  const cacheKey = `tasks:blueprint:${blueprintId}`;\n  \n  \u002F\u002F Check cache\n  if (this.cacheService.has(cacheKey)) {\n    return this.cacheService.get\u003CTask[]>(cacheKey)!;\n  }\n  \n  \u002F\u002F Load from repository\n  const tasks = await this.taskRepository.findByBlueprintId(blueprintId);\n  \n  \u002F\u002F Populate cache\n  this.cacheService.set(cacheKey, tasks, {\n    type: 'memory',\n    expire: 5 * 60 * 1000\n  });\n  \n  return tasks;\n}\n```\n\n## Best Practices\n\n### Cache Key Naming\n\n```typescript\n\u002F\u002F Good: Descriptive, hierarchical keys\n'users:123'\n'tasks:blueprint:abc-123'\n'config:app:theme'\n\n\u002F\u002F Bad: Generic, flat keys\n'user'\n'data123'\n'cache'\n```\n\n### TTL Guidelines\n\n```typescript\n\u002F\u002F Static data: 1 hour - 1 day\nthis.cacheService.set('config', data, { expire: 24 * 60 * 60 * 1000 });\n\n\u002F\u002F Dynamic data: 1-10 minutes\nthis.cacheService.set('tasks', data, { expire: 5 * 60 * 1000 });\n\n\u002F\u002F User-specific: Session duration\nthis.cacheService.set('user:prefs', data, { type: 'sessionStorage' });\n\n\u002F\u002F Persistent: 30 days\nthis.cacheService.set('settings', data, { \n  type: 'localStorage',\n  expire: 30 * 24 * 60 * 60 * 1000 \n});\n```\n\n## Checklist\n\nWhen implementing caching:\n\n- [ ] Choose appropriate cache type (memory\u002FlocalStorage\u002FsessionStorage)\n- [ ] Set reasonable TTL values\n- [ ] Implement cache invalidation on data changes\n- [ ] Use descriptive, hierarchical cache keys\n- [ ] Handle cache misses gracefully\n- [ ] Monitor cache hit\u002Fmiss rates\n- [ ] Consider cache size limits\n- [ ] Test cache expiration\n- [ ] Document caching strategy\n- [ ] Implement cache warming for critical data\n\n## References\n\n- [@delon\u002Fcache Documentation](https:\u002F\u002Fng-alain.com\u002Fcache)\n- [Caching Best Practices](https:\u002F\u002Faws.amazon.com\u002Fcaching\u002Fbest-practices\u002F)\n- [Cache Patterns](https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Fazure\u002Farchitecture\u002Fpatterns\u002Fcache-aside)\n",{"name":5,"license":14,"description":7},"master","08cc2532077058aa50e6e18f54695bc256c88152","skills\u002F7spade\u002Fdelon-cache-caching-strategies","https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub","https:\u002F\u002Fgithub.com\u002Fsuperhealth","java engineer","2026-04-06 22:07:23",{"source":8,"skillName":5,"commands":51,"prompt":61,"zipAvailable":62},[52,55,58],{"tool":53,"command":54},"npx","npx skills add superhealth\u002Fskills-hub --skill delon-cache-caching-strategies",{"tool":56,"command":57},"bunx","bunx skills add superhealth\u002Fskills-hub --skill delon-cache-caching-strategies",{"tool":59,"command":60},"pnpm","pnpm dlx skills add superhealth\u002Fskills-hub --skill delon-cache-caching-strategies","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub\u002Fblob\u002Fmaster\u002Fskills\u002F7spade\u002Fdelon-cache-caching-strategies\u002FSKILL.md",true,[64],{"path":65,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":68,"sourceHtmlUrl":69},"skill-report.json","REFERENCE","参考文档",13591,"https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub\u002Fblob\u002Fmaster\u002Fskills\u002F7spade\u002Fdelon-cache-caching-strategies\u002Fskill-report.json",[71,97,119,131,146,160],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":38},"01M6MC9F3WHV8S8FZ2W4TRB0FE","vercel-react-best-practices","React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React\u002FNext.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.","https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub\u002Fblob\u002Fmaster\u002Fskills\u002Fzhanlincui\u002Fvercel-react-best-practices\u002FSKILL.md",[],[78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,37,96],"react","vercel react best practices","best practices","vercel","react best practices","data fetching","code","triggers","pages","next","patterns","refactoring","data","Optimization","tasks","guidelines","react components","components","writing",{"skillNo":98,"name":99,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":38},"01M6MB8KWE1Q5A5KERR7RFTQWP","vue-testing-best-practices","Use for Vue.js testing. Covers Vitest, Vue Test Utils, component testing, mocking, testing patterns, and Playwright for E2E testing.","https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub\u002Fblob\u002Fmaster\u002Fskills\u002Fvuejs-ai\u002Fvue-testing-best-practices\u002FSKILL.md",[],[104,105,106,80,107,108,109,110,111,32,112,88,113,114,23,115,116,117,118],"vue testing best practices","testing best practices","vue","testing","testing patterns","js","e2e","vitest","component","test","mocking","utils","e2e testing","github","playwright",{"skillNo":120,"name":121,"nameZh":6,"description":122,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":123,"categories":124,"keywords":125,"publishedAt":38},"01M6MB8GK06M6GA4KVYNDV1BZP","vue-router-best-practices","Vue Router 4 patterns, navigation guards, route params, and route-component lifecycle interactions.","https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub\u002Fblob\u002Fmaster\u002Fskills\u002Fvuejs-ai\u002Fvue-router-best-practices\u002FSKILL.md",[],[80,106,126,127,128,88,129,130,112,117],"router","vue router best practices","route","navigation","lifecycle",{"skillNo":132,"name":133,"nameZh":6,"description":134,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":135,"categories":136,"keywords":137,"publishedAt":38},"01M6MB8DQF21TZMQ9XC3745ERW","vue-pinia-best-practices","Pinia stores, state management patterns, store setup, and reactivity with stores.","https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub\u002Fblob\u002Fmaster\u002Fskills\u002Fvuejs-ai\u002Fvue-pinia-best-practices\u002FSKILL.md",[],[138,139,106,80,140,141,88,142,143,144,145,117],"vue pinia best practices","pinia","with","store","management","state","state management","setup",{"skillNo":147,"name":148,"nameZh":6,"description":149,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":150,"categories":151,"keywords":152,"publishedAt":38},"01M6MB8A7MC08747J9TV4GWQ9A","vue-options-api-best-practices","Vue 3 Options API style (data(), methods, this context). Each reference shows Options API solution only.","https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub\u002Fblob\u002Fmaster\u002Fskills\u002Fvuejs-ai\u002Fvue-options-api-best-practices\u002FSKILL.md",[],[106,153,154,33,80,155,156,157,158,90,117,159],"options","vue options api best practices","methods","reference","only","context","style",{"skillNo":161,"name":162,"nameZh":6,"description":163,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":164,"categories":165,"keywords":166,"publishedAt":38},"01M6MB85ZTQC24Q04X49MM4YXN","vue-development-guides","A collection of best practices and tips for developing applications using Vue.js. This skill MUST be apply when developing, refactoring or reviewing Vue.js or Nuxt projects.","https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub\u002Fblob\u002Fmaster\u002Fskills\u002Fvuejs-ai\u002Fvue-development-guides\u002FSKILL.md",[],[167,106,168,169,117,170,171,23,172,173,174,109,89,175,176,80],"development","guides","vue development guides","tips","apply","project","nuxt","projects","collection","applications"]