nazg / hcache
cache that boosts performance
Installs: 6 196
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 1
Language:Hack
Requires
- hhvm: ^4.62
- hhvm/hhvm-autoload: ^3.0
- hhvm/hsl: ^4.0
- hhvm/hsl-experimental: ^4.25
Requires (Dev)
- facebook/fbexpect: ^2.7.3
- hhvm/hacktest: ^2.0.0
- hhvm/hhast: ^4.0.0
This package is auto-updated.
Last update: 2024-11-29 06:03:01 UTC
README
Installation
$ composer require nazg/hcache
Usage
supported apc, memcached, map, void, filesystem
Using the CacheManager
<?hh use Nazg\HCache\Element; use Nazg\HCache\CacheManager; $manager = new CacheManager(); $cache = $manager->createCache('memcached'); $mc = new \Memcached('mc'); $mc->addServers([['127.0.0.1', 11211]]); $cache->setMemcached($mc); $cache->createCache('map')?->save('cache', new Element('testing', 0));
Cache Usage
Retrieving Item From The Cache
<?hh <<__Override>> public function fetch(string $id): mixed { }
Checking For Item Existence
<?hh <<__Override>> public function contains(string $id): bool { }
Storing Item In The Cache
<?hh <<__Override>> public function save(string $id, Element $element): bool { }
Removing Items From The Cache
remove item
<?hh <<__Override>> public function delete(string $id): bool { }
flush
<?hh <<__Override>> public function flushAll(): bool { }
Adding Custom Cache Drivers
<?hh use Nazg\HCache\CacheManager; use Nazg\HCache\CacheProvider; $manager = new CacheManager(); $manager->addCache('null', () ==> new NullCache()); $manager->createCache('null'); class NullCache extends CacheProvider { <<__Override>> public function fetch(string $id): mixed { return; } <<__Override>> public function contains(string $id): bool { return false; } <<__Override>> public function save(string $id, Element $element): bool { return true; } <<__Override>> public function delete(string $id): bool { return true; } <<__Override>> public function flushAll(): bool { return true; } }
Using Cache Providers
example
FileSystemCache
<?hh use Nazg\HCache\Element; use Nazg\HCache\Driver\FileSystemCache; $cache = new FileSystemCache(); $cache->setDirectory(__DIR__ . '/../storages'); $cache->save('file', new Element('testing', 0)); $cache->fetch('file'); $cache->contains('file') $cache->flushAll();
MapCache (memory)
<?hh use Nazg\HCache\Element; use Nazg\HCache\Driver\MapCache; $cache = new MapCache(); $cache->save('map', new Element('testing', 0));
MemcachedCache
<?hh use Nazg\HCache\Element; use Nazg\HCache\Driver\MemcachedCache; $cache = new MemcachedCache(); $mc = new \Memcached('mc'); $mc->addServers([['127.0.0.1', 11211]]); $cache->setMemcached($mc); $cache->save("qwerty", new Element('testing:cache', 0));