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
Compatibility with PSR-6/PSR-16 #70
base: 2.4.x
Are you sure you want to change the base?
Conversation
Signed-off-by: codealfa <samuel@jch-optimize.net>
Signed-off-by: codealfa <samuel@jch-optimize.net>
Signed-off-by: codealfa <samuel@jch-optimize.net>
Signed-off-by: codealfa <samuel@jch-optimize.net>
Thanks! I will have a look on this when I find some time, might be this weekend. Afterwards, I start to implement v3 compat in all adapters and thus, could merge this PR as well (which might need some adjustments regarding the new major versions of PSR-16 an PSR-6. So there will be a bunch of new majors in the next weeks, pretty sure I can add this to the next major as well. Some quick thoughts:
I will double-check the reason on why the long key test skip message states that a maximum of 64 characters is supported. That seems to be incorrect and might've been a copy & paste issue. |
No worries. Happy for the chance to contribute. I was looking for a PSR-compliant caching system and found Laminas. I have been using it for about two years without the PSR decorators anyway to take advantage of some of the native features and fell in love with it, but now I've decided to implement PSR conformance in my project but was disappointed that the filesystem adapter didn't support it. I decided to share my integration, but if you decide on another implementation, that's ok too, as long as we have full PSR compatibility sooner than later.
You did mention in #7 your concern for much I/O with this implementation, with which I'm in total agreement. That's why I implemented it this way.
The only way I know how to address the storage of expired resources in the filesystem is by using the What I wasn't sure of was how you'd want to go about the deletion of expired files when they are requested. I think this should have minimum impact on program flow in the event the deletion wasn't successful. Anyway, whenever you've got a chance to review, you can decide how to move forward, and I'll be happy to assist in any way. |
Description
As requested in #7, I have implemented compatibility with
PSR-6
andPSR-16
in the filesystem adapter. Since the filesystem is the storage that is available on every server and hence the defacto storage, then at the very least, I think this adapter should support these standards.I have implemented static TTL capabilities by prepending a line containing a token with the expiration time when a file is saved to the cache. I have added another method,
expired
to theLocalFilesystemInteraction
class that reads the first line and verifies that the file is still valid. If the cache is expired, the file is deleted and the method returnstrue
, otherwisefalse
. This is done to avoid reading the entire file into memory only to check its status as in the case ofclearExpired
orgetTags
. If the file will be read as ingetItem
orgetItems
, then the expiration is checked after the file is read and appropriate action is taken to avoid reading the file twice. If the file is expired in either case, it is promptly deleted.Additionally, I have added the
.
character to the defaultKEY_PATTERN
inFilesystemOptions
to comply with thePSR-6
andPSR-16
requirements.I have also implemented the
FilesystemIntegrationTest
forPSR-6
and have removed all test skips relating to TTL and valid keys for bothPSR-6
andPSR-16
. The only test skipped now istestBasicUsageWithLongKey
, for which I did not understand the rationale. It is testing for a key length of 300 characters, and the skip message states, 'Filesystem adapter supports only 64 characters for a cache key'. However, the max key length in theFilesystem
adapter capabilities is nearly 255 and the PSR requirement is "up to 64 characters." In my opinion, the test would be more useful if testing for support of a minimum of 64 characters, and then we would not have to skip anything tests.Two more tests were added to
FilesystemTest
to verify files were deleted when expired, and that program flow wasn't interrupted if expired cache wasn't deleted immediately, but still reported as invalid.