Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix proposal 355 #358

Open
wants to merge 3 commits into
base: 4.2.x
Choose a base branch
from
Open

Fix proposal 355 #358

wants to merge 3 commits into from

Conversation

SvenRtbg
Copy link

Q A
Documentation no
Bugfix yes
BC Break no
New Feature no
RFC no
QA no

Description

I discovered that \Laminas\Cache\Pattern\ObjectCache, after being untangled and not inheriting from CallbackCache anymore, has changed the way the cache key computation is done and now is sensitive to all properties being present, and cannot deal with Closures present in them.

This is described in issue #355.

Expected behaviour (identical with V3.x):

  • ObjectCache allows to cache object trees that contain Closures, as they are not used to create a cache key.
  • ObjectCache is consistently creating the same cache key independent from any property values that are contained in the object tree.

Observed behavior with V4.0 up to v4.1.0:

  • ObjectCache throws an exception when encountering a Closure in a property.
  • ObjectCache creates differing cache keys if properties change inside the object tree.

This proposal adds a test case indicator by simply forcing a useless Closure into the \LaminasTest\Cache\Pattern\TestAsset\TestObjectCache, which prevents serializing this object.

Then a code path is added to CallbackCache that detects if an object is present in the PatternOptions, which is taken as an indicator we are dealing with ObjectCache forwarding the call into CallbackCache, and apply the previously existing cache key logic that was present in ObjectCache::generateCallbackKey() from version 3.x. This will restore the previous behavior.

This PR targets the 4.2.x branch, as there is currently only a minor lock file commit after the 4.1.x branch, and merging this fix may be considered serious enough to warrant a new minor release, as it reverts a major version change I consider to be accidental.

With the removal of inheritance between ObjectCache and CallbackCache,
the way cache keys are created changed for ObjectCache. Previously
CallbackCache was calling code in the ObjectCache class to create
a cache key based on the class name and method called.

This fix restores this by detecting if there is an object saved in the
PatternOptions, which is taken as an indicator we are dealing with the
ObjectCache use case.

As a side effect, this fix restores the ability to user-define the configuration
"object_key" in case multiple variants of the same class need to be
treated differently, as documented for ObjectCache pattern options.

resolves laminas#355

Signed-off-by: Sven Rautenberg <[email protected]>
The closure prevents the object from getting serialized, which should not
happen during tests, as the ObjectCache code path must not serialize the object.

Signed-off-by: Sven Rautenberg <[email protected]>
@SvenRtbg SvenRtbg force-pushed the fix-proposal-355 branch 5 times, most recently from ccf2b46 to 1263af4 Compare January 14, 2025 16:31
Signed-off-by: Sven Rautenberg <[email protected]>
@froschdesign froschdesign added Bug Something isn't working Review Needed labels Jan 30, 2025
@froschdesign
Copy link
Member

@boesing
Is this correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Review Needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants