g4/mcache

mcache php library

2.1.0 2024-04-18 07:47 UTC

README

mcache - php cache wrapper library

Install

Install through composer package manager. Find it on packagist.

composer require g4/mcache

Supported caching systems

Usage

Memcached instance

<?php
    
$driverName = 'Libmemcached';
$options = array(
    'servers' => array(
        '127.0.0.1:11211'
    );
);
$prefix = 'my_prefix';
    
$mcache = \G4\Mcache\McacheFactory::createInstance($driverName, $options, $prefix);

Couchbase instance

<?php
    
$driverName = 'Couchbase';
$options = array(
    'bucket' => 'my_bucket',
    'servers' => array(
        '127.0.0.1:8091'
    );
);
$prefix = 'my_prefix';
    
$mcache = \G4\Mcache\McacheFactory::createInstance($driverName, $options, $prefix);

Available options

* bucket - string
* servers - array
* user - string
* pass - string
* persistent - bool
* timeout - int (default 2500000)

Methods

<?php
    
// Get from cache
$value = $mcache
    ->key('my_key')
    ->get();
    
// Save to cache
$mcache
    ->key('my_key')
    ->value('my_value')
    ->set();
    
// Sava to cache with expiration
$mcache
    ->key('my_key')
    ->value('my_value')
    ->expiration(3600) // in seconds (default 0)
    ->set();
    
// Delete from cache
$mcache
    ->key('my_key')
    ->delete();
    
// Replace a value
$mcache
    ->key('my_key')
    ->value('my_value')
    ->replace();

Development

Install dependencies

$ make install

Run tests

$ make test

License

(The MIT License) see LICENSE file for details...