Cache is nearly final

Spent last week polishing yiisoft/cache. Now I think it looks good. It’s still based on original refactoring idea of @klimov-paul i.e. main Cache class is a wrapper that takes any PSR-16 implementation as constructor argument and extends it with extra features.

Detailed readme is available. Compared to Yii 2:

  1. It’s PSR-16 compatible so both you can use any PSR-16 implementation and the library itself could be used as a PSR-16 implementation.
  2. Cache storage implementations are more polished.
  3. It has modern PHP types.
  4. Expression dependency was replaced with Callback dependency.
  5. Chain dependency was split into Any and All.

There are multiple things to decide on before release though:

  1. Should clear() take key prefix into account?
  2. Do we need add() and addMultiple()? Are there use-cases for these?
  3. PSR-16 requires string keys but we’re supporting any types via serialization. Is this feature useful?
  4. Likely cache storage backends should be moved into separate repositories

Feedback is very welcome.


Are there any implementation issues with add(), addMultiple() or non-string keys?

No. They’re implemented.

Then why remove it? IMO support for non-string keys is quite convenient. I also don’t remember using add() or addMultiple() in case of cache, but I used similar methods for persistent storage and IMO it could be useful also for cache.

Both changes make component less useful and upgrade from Yii 2 harder, so if there are no good reasons to remove it, IMO they should stay.

1 Like

Nitpicking here but from looking at PSR-16 and the implementation only the storage backends implement PSR-16. I would consider “the library itself” to be the main Cache class - which is not PSR-16 compliant, mainly due to the keys.

Maybe it’s worth making this more clear?

Fixed that. Now implementing libraries are doing the check for reserverd characters and, if you pass string keys with these charactes in Cache, it will throw expected exception.

Fix looks good, but actually I meant something different. It should be made clear that Yiisoft\Cache\Cache itself is not compatible to PSR-16. Only the cache backends are. The sentence on the top of the README is a bit misleading IMO.

Alright. Fixed that in readme.