kozz / static-cache
Static Cache
Requires
- php: >=5.4.0
- doctrine/cache: *
- phpoption/phpoption: *
- symfony/dependency-injection: *
Requires (Dev)
Suggests
- php: >=5.6.5
This package is not auto-updated.
Last update: 2024-11-19 04:26:29 UTC
README
Static Cache with Repositories
About
You can use StaticCache
as simple cache tool that allows you access cached data from
every place of your application during runtime.
It doesn't stores data im memcached or some other data storage,
that's just static implementation of Doctrine's ArrayCache
The most powerful idea of this library is Repositories
Repositories
Repository allows you initialize some heavy library once and than it's instance with simple Object-Oriented Style
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:
//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
$validator = StaticCache::loadRepository(new SymfonyValidator()); //Validator initialized and saved in cache
//SomeOtherFile.php use Kozz\Components\Cache\StaticCache
$validator = StaticCache::loadRepository(new SymfonyValidator()); //Now validator just loaded from cache
### Reference
Methods
```get($id)``` - get
```set($id, $data)``` - set
```has($id)``` - check
```loadRepository(CacheRepositoryInterface $repository)``` - load Repository