PHP Classes


Recommend this page to a friend!
  Classes of Ujah Chigozie peter   PHP File Cache Library   Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP File Cache Library
Store in a cached data from by a callback function
Author: By
Last change:
Date: 11 months ago
Size: 1,249 bytes


Class file image Download


A simple php file cache


Installation is super-easy via Composer:

composer require peterujah/cache


Initialize DBController with configuration array

use Peterujah\NanoBlock\Cache;
$cache = new Cache("CACHE_NAME", __DIR__ . "/temp/caches/");

Query database and save response for later use

$user = $cache->onExpired("LIST", function () use($connConfig, $user_id){
	$conn_handler = new Peterujah\NanoBlock\DBController($connConfig);
	      SELECT * FROM user_table
	      WHERE user_id = :fund_user_id
	      LIMIT 1
	$conn_handler->bind(':fund_user_id', $user_id);
	$user = $conn_handler->getOne();
	return  array(
	    "user" => $user,
	    "time" => time(),
	    "morething" => "More"

Sets the cache debugging mode, the default is false


Sets the cache file extension type default is JSON

$cache->setExtension(Cache::PHP | Cache::JSON | Cache::TEXT);

Enable the cache to store secure data available only with php file extension, the default is true.

$cache->enableSecureAccess(true | false);