drago-fw/cache

Easier cache usage.


Keywords
caching, nette, nette-framework, php, storage
License
MIT

Documentation

Drago Caching

Codacy Badge

Easy to use cache.

Instruction

Add the configuration file:

services:

	# Cache settings.
	drago.cache:
		class: Nette\Caching\Cache
		arguments: [@Nette\Caching\IStorage, 'Drago.Caches']

	- Drago\Caching\Caches(@drago.cache)

Cache repository

$this->caches()->getCache();

Save to cache

$this->caches()->setToCache($key, $data);

Load from cache

$this->caches()->getFromCache($key);

Using the cache for database queries

Example for the database, first verify the existence of the cache, and if necessary create cache or read cache:


// Example for the database.
public function getAllData()
{
	$key = 'cache.db.table';
	if (!$this->caches->isCacheExist($key)) {
		$this->caches->setToCache($key, $this->db
			->query('SELECT * FORM table')
			->fetchAll());
	}

	if ($this->caches->isCacheExist($key)) {
		return $this->caches->getFromCache($key);
	}
}

Remove cache

$this->caches()->removeCache($key);

Verification of the existence cache

$this->caches()->isCacheExist($key);