Static Cache
, (*1)
Static Cache with Repositories, (*2)
About
You can use StaticCache
as simple cache tool that allows you access cached data from
every place of your application during runtime., (*3)
It doesn't stores data im memcached or some other data storage,
that's just static implementation of Doctrine's ArrayCache
, (*4)
The most powerful idea of this library is Repositories
, (*5)
Repositories
Repository allows you initialize some heavy library once and than it's instance with
simple Object-Oriented Style, (*6)
E.g.:
Assume are using Symfony Validator several times during the runtime.
That's bad idea initialize it every time in different places of the application so you can
easyly create SymfonyValidator Repository:, (*7)
//SymfonyValidator.php
class SymfonyValidator implements CacheRepositoryInterface
{
public funcnction getSingleton()
{
return Validation::createValidatorBuilder()
->enableAnnotationMapping(new CachedReader(new AnnotationReader(), new ArrayCache()))
->setMetadataCache(new DoctrineCache(new ArrayCache()))
->getValidator();
}
}
//SomeFile.php
use Kozz\Components\Cache\StaticCache, (*8)
$validator = StaticCache::loadRepository(new SymfonyValidator());
//Validator initialized and saved in cache, (*9)
//SomeOtherFile.php
use Kozz\Components\Cache\StaticCache, (*10)
$validator = StaticCache::loadRepository(new SymfonyValidator());
//Now validator just loaded from cache, (*11)
```, (*12)
Reference
Methods, (*13)
get($id)
- get, (*14)
set($id, $data)
- set, (*15)
has($id)
- check, (*16)
loadRepository(CacheRepositoryInterface $repository)
- load Repository, (*17)