Skip to content

feat: add limit option to useResponseCaching for entry eviction - #737

Merged
ascott18 merged 6 commits into
mainfrom
ascott18-api-client-cache-limits
Jun 30, 2026
Merged

feat: add limit option to useResponseCaching for entry eviction#737
ascott18 merged 6 commits into
mainfrom
ascott18-api-client-cache-limits

Conversation

@ascott18

Copy link
Copy Markdown
Collaborator

Summary

Adds a limit option to useResponseCaching() that constrains how many cached responses are stored per endpoint group. When limits are exceeded, the oldest entries are evicted first.

Configuration

caller.useResponseCaching({
  limit: {
    key: string,          // Custom group key (default: endpoint path without query params)
    maxEntries: number,   // Max cached entries per group
    maxBytes: number,     // Max total serialized size per group
  },
});

Implementation

  • Group metadata is stored in the same Storage alongside cache entries, using a coalesce:group: key prefix
  • Each group metadata entry tracks the cache key, timestamp, and serialized size of each member entry
  • On cache write, stale references (entries removed by purgeStaleCacheEntries or other means) are cleaned up from group metadata
  • The newest entry is never evicted, even if it alone exceeds maxBytes

Changes

  • src/coalesce-vue/src/api-client.ts - Added limit to ResponseCachingConfiguration type, added enforceGroupLimits() helper, updated cache write path
  • src/coalesce-vue/test/api-client.spec.ts - Tests for maxEntries, maxBytes, custom group keys, and stale reference cleanup
  • docs/stacks/vue/layers/api-clients.md - Updated documentation with limit option details and example
  • CHANGELOG.md - Added changelog entry

ascott18 and others added 5 commits June 26, 2026 14:54
Add limit configuration to ResponseCachingConfiguration that supports
maxEntries and maxBytes constraints per endpoint group. When limits are
exceeded, oldest cache entries are evicted first.

Group metadata is stored alongside cache entries in the same Storage
using a 'coalesce:group:' key prefix. The default group key is the
endpoint URL path without query parameters, and can be customized
via limit.key.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Allow limit.key to be a function (req, defaultKey) => string in
addition to a static string, for dynamic group key computation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds an optional limit configuration to useResponseCaching() in coalesce-vue to cap cached responses per endpoint group (by entry count and/or total serialized size), evicting oldest entries first. This extends the existing client-side response cache behavior and documents the new configuration for framework consumers.

Changes:

  • Extended ResponseCachingConfiguration with a limit option and implemented group metadata + eviction via enforceGroupLimits().
  • Added test coverage for maxEntries, maxBytes, custom group keys, function-based keys, and stale-reference cleanup.
  • Updated Vue API client docs and added a changelog entry describing the new option.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
src/coalesce-vue/src/api-client.ts Adds limit configuration, persists group metadata in Storage, and enforces per-group eviction on cache writes.
src/coalesce-vue/test/api-client.spec.ts Adds tests covering eviction behavior and group metadata handling.
docs/stacks/vue/layers/api-clients.md Documents the new limit option and provides an example.
CHANGELOG.md Notes the new limit option for useResponseCaching.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/coalesce-vue/src/api-client.ts
Comment thread src/coalesce-vue/src/api-client.ts
Comment thread src/coalesce-vue/src/api-client.ts
Comment thread src/coalesce-vue/src/api-client.ts
Comment thread src/coalesce-vue/test/api-client.spec.ts Outdated
Comment thread src/coalesce-vue/test/api-client.spec.ts Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@ascott18
ascott18 merged commit 847482f into main Jun 30, 2026
17 checks passed
@ascott18
ascott18 deleted the ascott18-api-client-cache-limits branch June 30, 2026 04:21
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.

2 participants