[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6EJ3QP35P58Q0NZRYKS90GS":3,"skill-same:01M6EJ3QP35P58Q0NZRYKS90GS":77},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":26,"publishedAt":43,"linkOnly":44,"markdownContent":45,"markdownBody":46,"frontMatter":47,"refName":48,"commitSha":49,"skillDirectory":50,"forksCount":51,"repositoryHtmlUrl":52,"repositoryHomepageUrl":53,"ownerHtmlUrl":54,"ownerBlogUrl":6,"ownerDescription":55,"updatedAt":56,"install":57,"resources":70},"01M6EJ3QP35P58Q0NZRYKS90GS","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.","ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",67,"MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002F7spade\u002Fdelon-cache-caching-strategies\u002FSKILL.md",[18,23],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000010","后端与接口","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发",[27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42],"cache","caching","strategies","caching strategies","delon cache caching strategies","memory","performance","implement","storage","http","database","api","use","queries","grouping","database queries","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":15,"description":7},"main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002Faiskillstore\u002Fmarketplace\u002F7spade\u002Fdelon-cache-caching-strategies",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":8,"skillName":5,"commands":58,"prompt":68,"zipAvailable":69},[59,62,65],{"tool":60,"command":61},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill delon-cache-caching-strategies",{"tool":63,"command":64},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill delon-cache-caching-strategies",{"tool":66,"command":67},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill delon-cache-caching-strategies","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002F7spade\u002Fdelon-cache-caching-strategies\u002FSKILL.md",true,[71],{"path":72,"resourceType":73,"resourceTypeDesc":74,"sizeBytes":75,"sourceHtmlUrl":76},"skill-report.json","REFERENCE","参考文档",13591,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002F7spade\u002Fdelon-cache-caching-strategies\u002Fskill-report.json",[78,88,98,107,113,120],{"skillNo":79,"name":80,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":84,"publishedAt":43},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[83],{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},[85,86,87],"model","model hierarchy","model hierarchy skill",{"skillNo":89,"name":90,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":91,"categories":92,"keywords":94,"publishedAt":43},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[93],{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},[95,96,97],"MCP","zoom","zoom mcp",{"skillNo":99,"name":100,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":43},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[104,105,106,96],"sdk","zoom apps sdk","apps",{"skillNo":108,"name":109,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":110,"categories":111,"keywords":112,"publishedAt":43},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[109],{"skillNo":114,"name":115,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":116,"categories":117,"keywords":119,"publishedAt":43},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[118],{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},[115],{"skillNo":121,"name":122,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":123,"categories":124,"keywords":125,"publishedAt":43},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[122]]