PHP code example of alirezaashrafi / php-file-cache

1. Go to this page and download the library: Download alirezaashrafi/php-file-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/ */

    

alirezaashrafi / php-file-cache example snippets


use AlirezaAshrafi\Cache;

use AlirezaAshrafi\Cache as FileCache;

$directory = __DIR__ . '/cache-dir';
$file = 'products';

$cache = new Cache($directory , $file);

// OR

$cache = new Cache(__DIR__ . '/cache-dir' , 'products');

$cache->set("product-1-name", "Iphone 13");
$cache->set("product-1-description", "Iphone 13 pro max 256G");

$product_name = $cache->get("product-1-name", "default value"); // "Iphone 13"
$product_name = $cache->get("product-2-name", "default value"); // "default value"

$cache->has("product-1-name"); // TRUE
$cache->has("product-2-name"); // FALSE

$cache->delete("product-1-description"); // TRUE

$cache->getAll();

$cache->purgeAll();

$ composer