PHP code example of hi-man / localcache

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

    

hi-man / localcache example snippets


$lc = new LocalCache(
  '127.0.01' /* redis host */,
  'Yac prefix' /* yac prefix, empty prefix will disable yac, default value is empty, max length is 20 */,
  6379 /* redis port, default value is 6379 */,
  3 /* redis connection timeout, in seconds, default value is 3 */,
  500000 /* redis retry interval, in microseconds, default value is 500000 */,
  3 /* redis read timeout, default value is 3 */,
  3 /* max retry, default value is 3 */,
  0 /* redis reserved, default value is 0 */
);

$lc->select(0 /* redis database index */);

$lc->get(
  'key' /* redis item key */,
  'default value' /* default value if the key does not exists */
);

$lc->set(
    'key',      /* redis item key */
    'value',    /* value to store */
    3           /* ttl */
    'default value' /* default value if the key does not exists */
);


$lc->delete(
    'key',      /* redis item key */
);

$lc->unlink(
    'key',      /* redis item key */
);

$lc->expire('key' /* redis item key */, 3 /* expire time in seconds */);

$lc->clear();

$lc->setLocalCacheTimeout(
    'key',      /* redis item key */
    'value',    /* value to store */
    3           /* ttl */
    'default value' /* default value if the key does not exists */
);


$lc->getLocalCacheTimeout();