PHP code example of originphp / cache

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

    

originphp / cache example snippets


Cache::config('default', [
    'engine' => 'File',
    'duration' => '+60 minutes', // string or number of seconds e.g. 3600,
    'prefix' => 'cache_'
    'serialize' => true // set to false if you going to cache strings such as output
    'path' => dirname(__DIR__) . '/cache'
     ]);

Use Origin\Cache\Cache;

$success = Cache::write('key',$value);

Use Origin\Cache\Cache;

$value = Cache::read('key');

Use Origin\Cache\Cache;

if(Cache::exists('key')){
    $bool = Cache::read('key');
}

Use Origin\Cache\Cache;

Cache::delete('key');

Cache::clear();

Cache::disable();
Cache::enable();

$cache = Cache::store('long-duration');
$value = $cache->read('My.key');

$value = Cache::read('My.key',[
     'config'=>'long-duration'
     ]);

Cache::config('default', [
    'engine' => 'File',
    'duration' => '+60 minutes', // string or number of seconds e.g. 3600,
    'prefix' => 'cache_'
    'serialize' => true // set to false if you going to cache strings such as output,
    'mode' => 0664
     ]);

Cache::config('default', [
    'engine' => 'Apcu',
    'duration' => '+60 minutes', // string or number of seconds e.g. 3600,
    'prefix' => 'cache_'
     ]);

Cache::config('default', [
        'engine' => 'Memcached',
        'host' => '127.0.0.1',
        'port' => '11211',
        'duration' => '+60 minutes', // string or number of seconds e.g. 3600,
        'prefix' => 'cache_'
     ]);

Cache::config('default', [
        'engine' => 'Memcached',
        'host' => '127.0.0.1',
        'port' => '11211',
        'username' => 'james',
        'password' => 'secret',
        'duration' => '+60 minutes', // 3600,
        'prefix' => 'cache_'
     ]);

Cache::config('default', [
     'engine' => 'Memcached',
     'path' => '/var/sockets/memcached'
     ]);

Cache::config('default', [
        'engine' => 'Redis',
        'host' => '127.0.0.1',
        'port' => 6379,
        'duration' => '+60 minutes', // string or number of seconds e.g. 3600,
        'timeout' => 0,
        'prefix' => 'cache_'
     ]);

Cache::config('default', [
        'engine' => 'Redis',
        'host' => '127.0.0.1',
        'port' =>  6379,
        'password' => 'secret',
        'duration' => 3600, // duration can also be string e.g. +60 minutes
        'prefix' => 'cache_'
     ]);

Cache::config('default', [
        'engine' => 'Redis',
        'path' => '/var/sockets/redis',
     ]);

Cache::config('default', [
        'engine' => 'Redis',
        'host' => '127.0.0.1',
        'port' => 6379,
        'persistent' => 'my-app',
        'duration' => 3600, // duration can also be string e.g. +60 minutes
        'timeout' => 0,
        'prefix' => 'cache_'
     ]);

Cache::config('default', [
    'className' => 'App\Cache\CustomEngine',
    'duration' => 3600,
    'prefix' => 'cache_'
     ]);

namespace App\Cache;
use Origin\Cache\Engine\BaseEngine;
class CustomEngine extends BaseEngine
{

}

sudo apt-get update
sudo apt-get install php-apcu
sudo echo 'apc.enable_cli=1' >>  /etc/php/7.2/cli/php.ini

sudo apt-get update
sudo apt-get install memcached
sudo apt-get install php-memcached

pecl install redis
sudo echo 'extension=redis.so' >> /etc/php/7.2/apache2/php.ini
sudo echo 'extension=redis.so' >> /etc/php/7.2/cli/php.ini

    php-memcached \

RUN pecl install redis
RUN echo 'extension=redis.so' >> /etc/php/7.2/apache2/php.ini
RUN echo 'extension=redis.so' >> /etc/php/7.2/cli/php.ini