Skip to content

perf: cache loaded templates in memory#129

Open
Darkroom4364 wants to merge 1 commit intoPwnKit-Labs:mainfrom
Darkroom4364:fix/template-caching
Open

perf: cache loaded templates in memory#129
Darkroom4364 wants to merge 1 commit intoPwnKit-Labs:mainfrom
Darkroom4364:fix/template-caching

Conversation

@Darkroom4364
Copy link
Copy Markdown
Contributor

  • Module-level cache avoids re-reading YAML on every call
  • clearTemplateCache() export for tests

Copy link
Copy Markdown
Contributor Author

@Darkroom4364 Darkroom4364 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scope: Only loader.ts + index.ts touched — confirmed, clean.

Cache logic: Correct. The cache stores the full unfiltered list; depth filtering is applied on read via .filter(), so a depth=passive call doesn't poison the cache for later depth=active calls. loadTemplateById benefits automatically since it calls loadTemplates().

One nit: loadTemplates returns _cache directly (not a copy). Any caller mutating the returned array (push/splice) would corrupt the cache. Returning [..._cache] (shallow copy) would be safer, but fine to skip if callers are read-only today.

clearTemplateCache is exported from both loader.ts and index.ts. LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant