PHP code example of quietasice / phpfastcache

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

    

quietasice / phpfastcache example snippets



/*
 * Welcome to Learn Lesson
 * This is very Simple PHP Code of Caching
 */

// Require Library
// Keep it Auto or setup it as "files","sqlite","wincache" ,"apc","memcache","memcached", "xcache"
e = phpFastCache("redis");

// Try to get $products from Caching First
// product_page is "identity keyword";
$products = $cache->get("product_page");

if($products == null) {
    $products = "DB QUERIES | FUNCTION_GET_PRODUCTS | ARRAY | STRING | OBJECTS";
    // Write products to Cache in 10 minutes with same keyword
    $cache->set("product_page",$products , 600);
}

// use your products here or return it;
echo $products;



/*
 * List of function and example
 */

$cache->set("keyword", "data | array | object", 300);
$cache->set("keyword", "data | array | object"); // <-- Non-Expired Objects without Time, until you delete the cache.

// Read from Cache | return "null" or "data"
$data = $cache->get("keyword");
echo $data;

// Temporary disabled phpFastCache
phpFastCache::$disabled = true;
$data = $cache->get("keyword");
echo $data; // ALWAYS RETURN NULL;

// Read object information | value | time from cache
$object = $cache->getInfo("keyword");
print_r($object);

// Delete from cache
$cache->delete("keyword");

// Clean up all cache
$cache->clean();

// Stats
$array = $cache->stats();
print_r($array);

// Increase and Decrease Cache value - Return  true | false
$cache->increment("keyword", 1);
$cache->decrement("keyword", 1);

// Extend expiring time - Return true | false;
$cache->touch("keyword", 1000);

// Check Existing or not - Return true | false;
$cache->isExisting("keyword");

// Get & Set Multiple Items
// Same as above, but input is array();

$list = $cache->getMulti(array("key1","key2","key3"));

$list = $cache->getInfoMulti(array("key1","key2","key3"));

$cache->setMulti(array("key1","value1", 300),
    array("key2","value2", 600),
    array("key3","value3", 1800));

$cache->deleteMulti(array("key1","key2","key3"));

$cache->isExistingMulti(array("key1","key2","key3"));

$cache->touchMulti(array(
                    array("key", 300),
                    array("key2", 400),
                   ));

$cache->incrementMulti(array(
                        array("key", 1),
                        array("key2", 2),
                    ));

$cache->decrementMulti(array(
                        array("key", 1),
                        array("key2", 2),
                    ));