Hi everyone,
PSR-6 covers caching, and it's just gone into the Review stage, which means that it's potentially not too far off from being accepted.
The details of it are here:
In general, I think it's worth us trying to adopt PSRs for future major releases of SilverStripe where we can, as it will seriously improve the ease with which developers can use SilverStripe alongside other projects. So, I think we should seriously consider replacing the back-end of SS_Cache with a PSR-6 compatible cache implementation. We can link to a default library and let people swap out the default library with another one using the Injector.
The cache API that it exposes is a bit more verbose than what we've previously used. The
cache-meta.md URL provides a good run-down of why they've tried to go this way. However, it begs the question: do we want to expose PSR-6 style API across all modules, or wrap it in a simplified API? The problem with wrapping it in a simplified API is that we're preserving a piece of coupling that we could otherwise remove.
Alternatively, we could build some more effective idioms for accessing caches as a standalone class that takes a PSR-6 cacher as a dependency. For example, you may define a closure that is executed only on a cache-miss.
$result = $cacher->getCached('cache-key', function() use($x) {
return $x->doSomethingHard();
});
I could imagine that a standalone library that provided a few of these kinds of idioms around a PSR-6 core would be quite handy. I'm not sure if there are projects like this out in the wild, or if we should kick one off. If one doesn't currently exist, my preference would be to start it as a standalone project with minimal dependencies, and link it into SilverStripe, rather than making it one among 100s of classes in silverstripe/framework.
As a further point, I've got no idea of which caching library would be best to use, and we'd want to research that. A robust library with minimal dependencies and a good number of back-end implementations would be ideal. It's possible that Zend is still the best option (although doctrine/cache seems very popular). We'd want to confirm whether the relevant library was planning on implementing PSR-6, and ideally, we'd incorporate it after they have done so.
So, a bunch of vague early-stage thoughts right now, but I thought it a good time to get discussion started. What do people think?
Thanks,
Sam