coercive / cache
Coercive Utility Cache
Installs: 1 308
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=7.4
- ext-json: *
README
Simple cache helpers.
Get
composer require coercive/cache
JSON
use Coercive\Utility\Cache # Load your cache instance for a defined project $json = new Json('/temp/my_project_directory') # Set a global default expire delay $json = new Json('/temp/my_project_directory', 'P1D') # OR $json->setExpireDelay('P1D') # Retrieve your data $data = $json->get('data-key') # Save your data $json->set('data-key', ['data1', 'data2']) # Save your data with specific expire delay $json->set('data-key', ['data1', 'data2'], 'PT15M') # Delete specific data $json->delete('data-key') # Empty cache $json->clear() # You can enable/disable the cache $json->disable() $json->enable() $json->setState(bool) # If cache disable $json->get('data-key') => return null
PHP
use Coercive\Utility\Cache # Load your cache instance for a defined project $php = new Php('/temp/my_project_directory') # Set a global default expire delay $php = new Php('/temp/my_project_directory', 'P1D') # OR $php->setExpireDelay('P1D') # Retrieve your data $data = $php->get('data-key') # Save your data $php->set('data-key', ['data1', 'data2']) # Save your data with specific expire delay $php->set('data-key', ['data1', 'data2'], 'PT15M') # Delete specific data $php->delete('data-key') # Empty cache $php->clear() # You can enable/disable the cache $php->disable() $php->enable() $php->setState(bool) # If cache disable $php->get('data-key') => return null
Global
use Coercive\Utility\Cache # Use debug method to handle exceptions $cache->debug(function($e) { /** @var Exception $e */ echo $e->getMessage(); // do something }); # You can also expose all exceptions var_dump($cache->getExceptions());