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

Introduce TTL per item along with value serialization #91

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

boesing
Copy link
Member

@boesing boesing commented Jul 9, 2024

Q A
Documentation yes
BC Break yes
New Feature yes

Description

This patch introduces TTL per item. The Filesystem adapter now may consume a ClockInterface which provides the current timestamp. When a cache item is written to the filesystem, an expiry date is being calculated which is written together with the cache value to the cache file. The cache value is serialized before written to the cache file which also adds more accurate type support to the Filesystem adapter. By having data serialized, we also introduced a new Filesystem option: unserializable_classes. This option is set to true by default which means that every object written to a cache file is properly unserialized after. Due to security implications, we recommend setting specific classes to be allowed to get unserialized. Unserialization of objects can also be disabled by providing false via the filesystem options.

By having serialization within the Filesystem adapter itself, the Serializer plugin is not needed anymore. The plugin will still work but every cache read/write will serialize twice.

Since the cache file format has been changed, we are dropping the options to modify both suffix and tag_suffix via FilesystemOptions. The tag suffix will remain as before while the cache file suffix (suffix) got replaced with cache to ensure that projects may not end up with corrupted cache files.

This patch will fully support PSR-6 and PSR-16 for the Filesystem adapter.

closes #7

@boesing boesing added this to the 3.0.0 milestone Jul 9, 2024
boesing added a commit to boesing/laminas-cache that referenced this pull request Jul 9, 2024
Ref: laminas/laminas-cache-storage-adapter-filesystem#91
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
@boesing boesing requested a review from gsteel July 9, 2024 21:38
/**
* {@inheritDoc}
*/
protected function internalGetItems(array $normalizedKeys): array
Copy link
Member Author

Choose a reason for hiding this comment

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

Might be problematic, haven't had a proper test yet but I could imagine that due to the block logic, this method was actually able to re-read a blocked cache item. I am not 100% sure if this will continue work but that would be a problem for a single read as well, which should then be addressed there which fixes both.

The abstract cache adapter itself does internally loop over those keys and reads them one-by-one and thats why having a fix there would be the better option IMHO. WDYT?

This patch introduces TTL per item. The `Filesystem` adapter now may consume a `ClockInterface` which provides the current timestamp. When a cache item is written to the filesystem, an expiry date is being calculated which is written together with the cache value to the cache file.
The cache value is serialized before written to the cache file which also adds more accurate type support to the `Filesystem` adapter. By having data serialized, we also introduced a new `Filesystem` option: `unserializable_classes`.
This option is set to `true` by default which means that every object written to a cache file is properly unserialized after. Due to security implications, we recommend setting specific classes to be allowed to get unserialized. Unserialization of objects can also be disabled by providing `false` via the filesystem options.

By having serialization within the `Filesystem` adapter itself, the `Serializer` plugin is not needed anymore. The plugin will still work but every cache read/write will serialize twice.

Since the cache file format has been changed, we are dropping the options to modify both `suffix` and `tag_suffix` via `FilesystemOptions`.
The `tag` suffix will remain as before while the cache file suffix (`suffix`) got replaced with `cache` to ensure that projects may not end up with corrupted cache files.

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
Copy link
Member

@gsteel gsteel left a comment

Choose a reason for hiding this comment

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

All looks good to me - I don't know cache very well though!

@boesing boesing merged commit 6d017b3 into laminas:3.0.x Jul 10, 2024
12 of 13 checks passed
@boesing boesing deleted the feature/ttl-per-item branch July 10, 2024 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compatibility with PSR-16/PSR-6
2 participants