DoctrineExtensions icon indicating copy to clipboard operation
DoctrineExtensions copied to clipboard

[SoftDeleteable] Remove dollar sign from cache key

Open adambalint-srg opened this issue 4 months ago • 11 comments

This PR removes dollar sign ($) from the default cache key. It's not a globally reserved characters in filenames, but there are cases when it can cause problems, as I read. This is why e.g. Laminas's filesystem cache disables this character. I think using __ instead of _$ isn't a problem, and won't cause any problems.

adambalint-srg avatar Aug 22 '25 10:08 adambalint-srg

Hi, do you have any example when it's an issue ?

VincentLanglet avatar Sep 14 '25 21:09 VincentLanglet

In my application (Laminas+Doctrine stack) I'm using this repo's extensions, and for Doctrine I'm using Laminas's filesystem cache. So the cacheId extension metadata will be used in file system cache. Now it throws an error. I've created a quick example where you can reproduce:

{
    "name": "test/test",
    "require": {
		"php": "^8.3",
		"laminas/laminas-cache-storage-adapter-filesystem": "^3.1.0",
		"gedmo/doctrine-extensions": "^3.20.1"
	}
}
<?php

declare(strict_types=1);

include 'vendor/autoload.php';

use Gedmo\Mapping\ExtensionMetadataFactory;
use Laminas\Cache\Storage\Adapter\Filesystem;

$cacheId = ExtensionMetadataFactory::getCacheId('Foo', 'Bar');
//cacheId is 'Foo_$BAR_CLASSMETADATA';

$fileSystemCache = new Filesystem();
$fileSystemCache->addItem($cacheId, ['some' => 'data']);
//Uncaught Laminas\Cache\Exception\InvalidArgumentException: The key 'Foo_$BAR_CLASSMETADATA' doesn't match against pattern '/^[a-z0-9_\+\-\.]*$/Di'

adambalint-srg avatar Sep 15 '25 05:09 adambalint-srg

Since this library requires a PSR-6 cache, and from what I can tell the Laminas cache doesn't directly implement that PSR (it does provide a decorator for this), is there an issue when you use their PSR-6 decorator with this library? (On a side note, I'd say the ExtensionMetadataFactory::getCacheId() really should've been marked internal and not used externally or in the exact way that reproducer snippet is written, but it's a little late for that now)

From a practical perspective, there isn't an issue with this PR (and presumably improves PSR-6 compatibility by ensuring only characters the spec explicitly says an implementation must support are used). But, it seems that the MongoDB ODM also uses a dollar sign in its cache keys which would imply that ODM and Laminas Cache are incompatible for the same reason.

mbabker avatar Sep 15 '25 13:09 mbabker

@mbabker I'm using PSR-6 decorator in my application. But this decorator does nothing with the cache keys.

/** @var StorageAdapterFactoryInterface $storageFactory */
		$storageFactory = $container->get(StorageAdapterFactoryInterface::class);

		/** @var StorageInterface&FlushableInterface $fileCache */
		$fileCache = $storageFactory->create('filesystem', $options);

		return new CacheItemPoolDecorator($fileCache);

The direct use of the getCacheId is only for this example, I don't use it directly.

adambalint-srg avatar Sep 16 '25 06:09 adambalint-srg

@phansys Changelog has been updated

adambalint-srg avatar Sep 22 '25 10:09 adambalint-srg

I think a new rebase is needed since 3.21 is released

VincentLanglet avatar Sep 22 '25 17:09 VincentLanglet

@VincentLanglet Sorry for mixing changelog parts. Is it OK now?

adambalint-srg avatar Sep 23 '25 08:09 adambalint-srg

@VincentLanglet Sorry for mixing changelog parts. Is it OK now?

I think it is. It's on @phansys side now

VincentLanglet avatar Sep 23 '25 08:09 VincentLanglet

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 78.75%. Comparing base (c9cafa6) to head (b3e7b0d). :warning: Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2978   +/-   ##
=======================================
  Coverage   78.75%   78.75%           
=======================================
  Files         169      169           
  Lines        8695     8695           
=======================================
  Hits         6848     6848           
  Misses       1847     1847           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Sep 23 '25 09:09 codecov[bot]

@phansys @VincentLanglet Is there anything what is still problematic with this PR? Or for what we are waiting? I'm still on a fork in my projects, and the production is coming :)

adambalint-srg avatar Dec 09 '25 08:12 adambalint-srg

It's on @phansys side, I dont have any right on this project

VincentLanglet avatar Dec 09 '25 08:12 VincentLanglet

@phansys @VincentLanglet Is there anything what is still problematic with this PR? Or for what we are waiting? I'm still on a fork in my projects, and the production is coming :)

From my side, the only request that is waiting for resolution is this: https://github.com/doctrine-extensions/DoctrineExtensions/pull/2978#discussion_r2373700631.

phansys avatar Dec 13 '25 19:12 phansys

@phansys I did a changelog update after this unresolved comment (9f129431ebf97764d18389dceb876a0e4279390f), but didn't get any update or feedback about this.

adambalint-srg avatar Dec 15 '25 06:12 adambalint-srg

@phansys I did a changelog update after this unresolved comment (9f12943), but didn't get any update or feedback about this.

IMO, the update is correct. Thank you.

Currently, the commits in this PR require a rebase to allow the merge.

Could you please perform a rebase @adambalint-srg?

phansys avatar Dec 15 '25 19:12 phansys

@phansys Currently I can't see any commits to rebase. Yesterday I did a conflict resolve, and it says now my branch is ahead of main, and not behind. Or I don't see something?

adambalint-srg avatar Dec 16 '25 09:12 adambalint-srg

@phansys Currently I can't see any commits to rebase. Yesterday I did a conflict resolve, and it says now my branch is ahead of main, and not behind. Or I don't see something?

This PR currently contains more commits than those related to your changes: image

This situation introduces conflicts that prevent the PR to be merged using the Rebase strategy:

image

phansys avatar Dec 16 '25 19:12 phansys

@phansys I don't know how it happened, but now it seems OK for me

adambalint-srg avatar Dec 17 '25 07:12 adambalint-srg

Thank you @adambalint-srg!

phansys avatar Dec 19 '25 18:12 phansys