1. Go to this page and download the library: Download anik/cache library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
anik / cache example snippets
if (!is_null($this->cache)){
$this->cache->set($key,$value,$ttl);
}
if (!is_null($this->cache)){
$this->cache->get($key)
}
use Psr\Cache\CacheItemInterface;
public function getItem(string $key): CacheItemInterface;
public function getItems(array $keys): CacheItemInterface[];
public function hasItem(string $key): bool;
public function clear(): bool;
public function deleteItem(string $key): bool;
public function deleteItems(array $keys): bool;
public function save(CacheItemInterface $item): bool;
public function saveDeferred(CacheItemInterface $item): bool;
public function commit(): bool;
public function getKey(): string;
public function get(): mixed;
public function isHit(): bool;
public function set(mixed $value): static;
public function expiresAt(\DateTimeInterface|null $expiration): static;
public function expiresAfter(\DateInterval|int|null$time): static;
public function getExpiration(): ?int;
public function getValue(): mixed;
use Psr\Cache\CacheItemInterface;
public function getItem(string $key): CacheItemInterface;
public function getItems(array $keys): CacheItemInterface[];
public function hasItem(string $key): bool;
public function clear(): bool;
public function deleteItem(string $key): bool;
public function deleteItems(array $keys): bool;
public function save(CacheItemInterface $item): bool;
public function saveDeferred(CacheItemInterface $item): bool;
public function commit(): bool;
public function get(string $key, mixed $default = null): mixed;
public function set(string $key, mixed $value, \DateInterval|int|null $ttl = null): bool;
public function delete(string $key): bool;
public function clear(): bool;
public function getMultiple(iterable $keys, mixed $default = null): iterable;
public function setMultiple(iterable $values, \DateInterval|int|null $ttl = null): bool;
public function deleteMultiple(iterable $keys): bool;
public function has(string $key): bool;
use Anik\Cache\Item;
use Anik\Cache\Pool\NullPool;
$pool = new NullPool();
// $pool = new NullPool($defaultReturnValue);
// $pool = new InMemoryPool();
// Item to store
$item = new Item('key-1', 'value-1');
// $item = new Item('key-2', 'value-2');
// Item expiration
// $item->expiresAfter(10);
// $item->expiresAt(($now = new DateTimeImmutable())->modify('+100 seconds'))
// save item
$pool->save($item);
// save deferred
$pool->saveDeferred($item);
$pool->commit();
// get item
$item = $pool->getItem('key-1');
$item->isHit();
$item->get();
// get multiple items
$pool->getItems(['key-1', 'key-2']);
// has item
$pool->hasItem('key-1');
// delete item
$pool->deleteItem('key-1');
// delete multiple items
$pool->deleteItems(['key-1', 'key-2']);
// clear pool
$pool->clear();
use Anik\Cache\Item;
use Anik\Cache\Pool\NullPool;
use Anik\Cache\PoolAdapter;
// pass the type of pool you want to use
$adapter = new PoolAdapter(new NullPool());
// $adapter = new PoolAdapter(new NullPool($defaultReturnValue));
// $adapter = new PoolAdapter(new InMemoryPool());
// can achieve the same using the helper methods
// $adapter = null_cache();
// $adapter = null_cache($defaultReturnValue);
// $adapter = in_memory_cache();
// Item to store
$item = new Item('key-1', 'value-1');
// $item = new Item('key-2', 'value-2');
// Item expiration
// $item->expiresAfter(10);
// $item->expiresAt(($now = new DateTimeImmutable())->modify('+100 seconds'))
// save/save deferred item
$adapter->save($item);
$adapter->saveDeferred($item);
$adapter->commit();
// Otherwise,
$adapter->set('key-3', 'value-3');
// get item
$item = $adapter->getItem('key-1');
$item->isHit();
$item->get();
// Otherwise
$adapter->get('key-3');
// get multiple items
$adapter->getItems(['key-1', 'key-2']);
// Otherwise
$adapter->getMultiple(['key-1', 'key-4'], 'default-value');
// has item
$adapter->hasItem('key-1');
// otherwise
$adapter->has('key-1');
// delete item
$adapter->deleteItem('key-1');
// delete multiple items
$adapter->deleteItems(['key-1', 'key-2']);
// Otherwise
$adapter->deleteMultiple(['key-1', 'key-2']);
// clear pool
$adapter->clear();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.