-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Conversation
Ref: laminas/laminas-cache-storage-adapter-filesystem#91 Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function internalGetItems(array $normalizedKeys): array |
There was a problem hiding this comment.
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>
e63a662
to
3eec18d
Compare
There was a problem hiding this 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!
Description
This patch introduces TTL per item. The
Filesystem
adapter now may consume aClockInterface
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 theFilesystem
adapter. By having data serialized, we also introduced a newFilesystem
option:unserializable_classes
. This option is set totrue
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 providingfalse
via the filesystem options.By having serialization within the
Filesystem
adapter itself, theSerializer
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
andtag_suffix
viaFilesystemOptions
. Thetag
suffix will remain as before while the cache file suffix (suffix
) got replaced withcache
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