sirbrillig / phpcs-changed

🐘 Run phpcs on files and only report new warnings/errors compared to the previous version.
MIT License
31 stars 11 forks source link

Refactor CacheInterface so that it deals only with a value object #45

Closed sirbrillig closed 3 years ago

sirbrillig commented 3 years ago

Cache interfaces shouldn't need to know the internal workings of the CacheManager, nor have direct access to it. That's a leaky abstraction. They should just be concerned with saving the state of the cache to storage and loading it again.

In this PR I introduce a value object for the state of the cache, called CacheObject. Mostly it's a collection of CacheEntry objects but there's also a few metadata values which are kept by the state: revisionId and cacheVersion. Each cache interface now just has to persist a CacheObject and return one. If more cache interfaces are introduced in the future, this should greatly simplify their APIs.