Overview

Namespaces

  • None
  • Wei
    • Validator

Classes

  • Apc
  • App
  • ArrayCache
  • Asset
  • Base
  • BaseCache
  • BaseController
  • Bicache
  • Cache
  • Config
  • Cookie
  • Couchbase
  • Counter
  • Db
  • DbCache
  • E
  • Env
  • Error
  • FileCache
  • Gravatar
  • Http
  • Lock
  • Logger
  • Memcache
  • Memcached
  • MongoCache
  • Password
  • PhpError
  • PhpFileCache
  • Pinyin
  • Record
  • Redis
  • Request
  • Response
  • Router
  • SafeUrl
  • Session
  • Soap
  • T
  • Ua
  • Upload
  • Url
  • Uuid
  • Validate
  • View
  • WeChatApp
  • Wei
  • Overview
  • Namespace
  • Class

Class BaseCache

The base class for cache services

Wei\Base
Extended by Wei\BaseCache

Direct known subclasses

Wei\Apc, Wei\ArrayCache, Wei\Redis, Wei\Bicache, Wei\Cache, Wei\Couchbase, Wei\DbCache, Wei\FileCache, Wei\Memcache, Wei\Memcached, Wei\MongoCache

Indirect known subclasses

Wei\PhpFileCache
Abstract
Namespace: Wei
Author: Twin Huang twinhuang@qq.com
Located at BaseCache.php
Methods summary
public mixed
# __invoke( string $key, mixed $value = null, integer $expire = 0 )

Retrieve or store an item

Retrieve or store an item

Parameters

$key
The name of item
$value
The value of item
$expire
The expire seconds, defaults to 0, means never expired

Returns

mixed
abstract public mixed
# get( string $key, integer $expire = null, callable $fn = null )

Retrieve an item

Retrieve an item

$cache = wei()->cache;

// Retrieve cache by key
$cache->get('key');

// Get cache value from callback
$cache->get('key', function($wei){ return 'value';
});

// Get cache value from callback with timeout
$cache->get('key', 10, function($wei){ return 'value';
});

Parameters

$key
The name of item
$expire
The expire seconds of callback return value
$fn
The callback to execute when cache not found

Returns

mixed

Throws

RuntimeException
When set cache return false
protected mixed
# processGetResult( string $key, mixed $result, integer $expire, callable $fn )

Store data to cache when data is not false and callback is provided

Store data to cache when data is not false and callback is provided

Parameters

$key
$result
$expire
$fn

Returns

mixed

Throws

RuntimeException
InvalidArgumentException
abstract public boolean
# set( string $key, mixed $value, integer $expire = 0 )

Store an item

Store an item

Parameters

$key
The name of item
$value
The value of item
$expire
The expire seconds, defaults to 0, means never expired

Returns

boolean
abstract public boolean
# remove( string $key )

Remove an item

Remove an item

Parameters

$key
The name of item

Returns

boolean
abstract public boolean
# exists( string $key )

Check if an item is exists

Check if an item is exists

Parameters

$key

Returns

boolean
abstract public boolean
# add( string $key, mixed $value, integer $expire = 0 )

Add an item

Add an item

Parameters

$key
The name of item
$value
The value of item
$expire
The expire seconds, defaults to 0, means never expired

Returns

boolean
abstract public boolean
# replace( string $key, mixed $value, integer $expire = 0 )

Replace an existing item

Replace an existing item

Parameters

$key
The name of item
$value
The value of item
$expire
The expire seconds, defaults to 0, means never expired

Returns

boolean
abstract public integer|false
# incr( string $key, integer $offset = 1 )

Increment an item

Increment an item

Parameters

$key
The name of item
$offset
The value to increased

Returns

integer|false
Returns the new value on success, or false on failure
public integer|false
# decr( string $key, integer $offset = 1 )

Decrement an item

Decrement an item

Parameters

$key
The name of item
$offset
The value to be decreased

Returns

integer|false
Returns the new value on success, or false on failure
public array
# getMulti( array $keys )

Retrieve multiple items

Retrieve multiple items

Parameters

$keys
The name of items

Returns

array
public array
# setMulti( array $keys, integer $expire = 0 )

Store multiple items

Store multiple items

Parameters

$keys
The name of items
$expire

Returns

array
public mixed
# getFileContent( string $file, callable $fn )

Use the file modify time as cache key to store an item from a callback

Use the file modify time as cache key to store an item from a callback

Parameters

$file
The path of file
$fn
The callback to get and parse file content

Returns

mixed
public string
# getNamespace( )

Returns the key prefix

Returns the key prefix

Returns

string
public
# setNamespace( string $namespace )

Set the cache key prefix

Set the cache key prefix

Parameters

$namespace

Returns


$this
abstract public boolean
# clear( )

Clear all items

Clear all items

Returns

boolean
Methods inherited from Wei\Base
__call(), __construct(), __get(), getOption(), setOption()
Properties summary
protected string $namespace

The string prepend to the cache key

The string prepend to the cache key

# ''
Properties inherited from Wei\Base
$providers, $wei
Wei Framework API documentation generated by ApiGen