Skip to content

Hotfix/cache issue fix - #675

Open
homestar9 wants to merge 2 commits into
ColdBox:developmentfrom
homestar9:hotfix/cache-issue-fix
Open

Hotfix/cache issue fix#675
homestar9 wants to merge 2 commits into
ColdBox:developmentfrom
homestar9:hotfix/cache-issue-fix

Conversation

@homestar9

Copy link
Copy Markdown
Contributor

Description

This PR fixes a bug where a dynamic EVENT_CACHE_SUFFIX closure was only evaluated once and then reused for every request. This could cause different requests, such as pages with different slugs or locales, to share the same cache key and return the wrong cached content.

The closure is now evaluated for each request (on cache misses) and receives the current request context, while existing single-argument closures and static suffixes continue to work as before. New tests reproduce the original bug and confirm that each request now uses the correct cache entry.

Jira Issues

https://ortussolutions.atlassian.net/browse/COLDBOX-1411

Type of change

  • Bug Fix

Checklist

  • My code follows the style guidelines of this project cfformat
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

… first request

The docs say EVENT_CACHE_SUFFIX can be a closure evaluated at runtime, but
HandlerService.getEventCachingMetadata() evaluates it once and memoizes the
result for the life of the app. Two of these specs fail on current code:

- 'evaluates a closure suffix on every request producing distinct cache keys'
  The needle [-beta-] was not found in
  [cbox_event-eventcachingsuffix.index-alpha-FBEE7A3D7291A76924037D5B7F2AE52E]
- 'keeps the closure in the memoized dictionary entry after requests'
  Expected [false] to be true
…the first value

The memoized eventCacheDictionary entry now stores the closure as declared.
Both read points resolve it for the current request on a shallow copy via the
new private resolveCacheSuffix():

- Store side: getEventCachingMetadata() resolves with the in-flight handler bean.
- Serve side: getEventMetadataEntry() resolves via getHandlerBean(), with an
  isSimpleValue() fast path so static suffixes skip the work.

The closure now also receives the request context as a second argument:
this.EVENT_CACHE_SUFFIX = function( eventHandlerBean, event ){ ... }
Existing single-argument closures keep working.

The closure runs twice per request (serve-side lookup + store-side key build),
so it must read request-stable inputs (rc, session, locale) and never time or
randomness - the same contract the hashed rc already has.

All EventCachingSpec specs pass, including the two that failed before this
change; full integration suite green (86/86 on BoxLang).
Copilot AI review requested due to automatic review settings July 28, 2026 18:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a bug in ColdBox event caching where a dynamic EVENT_CACHE_SUFFIX closure could be evaluated once and then effectively “frozen” into the memoized metadata entry, causing different requests (e.g., varying slug/locale) to share the same cache key and potentially serve incorrect cached content.

Changes:

  • Update HandlerService to store EVENT_CACHE_SUFFIX “as declared” (closure or static value) and resolve closure-based suffixes per request via a new resolveCacheSuffix() path.
  • Add integration specs that reproduce the original issue and verify per-request suffix evaluation and key consistency between serve-side lookup and store-side key building.
  • Introduce a dedicated test-harness handler fixture (eventcachingSuffix) to isolate suffix behavior from other event caching specs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/specs/integration/EventCachingSpec.cfc Adds integration tests covering per-request evaluation and key consistency for EVENT_CACHE_SUFFIX.
test-harness/handlers/eventcachingSuffix.cfc Adds a dedicated handler fixture whose cache key varies only by suffix derived from request context.
system/web/services/HandlerService.cfc Changes event cache metadata handling to avoid freezing request-time suffix values; introduces per-request suffix resolution helper.

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

Comment thread system/web/services/HandlerService.cfc
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