Skip to content

Commit

Permalink
Restore ObjectCache key creation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
srkdg committed Jan 13, 2025
1 parent bffe874 commit ebf2daf
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Pattern/CallbackCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ public function generateKey(callable $callback, array $args = []): string
*/
protected function generateCallbackKey(callable $callback, array $args): string
{

// Create a cache key for the ObjectCache use case.
$options = $this->getOptions();
if (is_object($options->getObject())) {
$callbackKey = md5($options->getObjectKey() . '::' . strtolower($callback[1]));
$argumentKey = $this->generateArgumentsKey($args);
return $callbackKey . $argumentKey;
}

if (! is_callable($callback, false, $callbackKey)) {
throw new Exception\InvalidArgumentException('Invalid callback');
}
Expand Down

0 comments on commit ebf2daf

Please sign in to comment.