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 DbCache

A cache service that stored data in databases

Wei\Base
Extended by Wei\BaseCache
Extended by Wei\DbCache
Namespace: Wei
Author: Twin Huang twinhuang@qq.com
Located at DbCache.php
Methods summary
public
# __construct( array $options = array() )

Constructor

Constructor

Parameters

$options

Throws

InvalidArgumentException
When option "wei" is not an instance of "Wei\Wei"

Overrides

Wei\Base::__construct()
public
# prepareTable( )

Check if table exists, if not exists, create table

Check if table exists, if not exists, create table

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

Retrieve an item

Retrieve an item

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
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
public boolean
# remove( string $key )

Remove an item

Remove an item

Parameters

$key
The name of item

Returns

boolean
public boolean
# exists( string $key )

Check if an item is exists

Check if an item is exists

Parameters

$key

Returns

boolean
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
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
public integer|false
# incr( string $key, integer $offset = 1 )

Note: This method is not an atomic operation

Note: This method is not an atomic operation

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 boolean
# clear( )

Clear all items

Clear all items

Returns

boolean
Methods inherited from Wei\BaseCache
__invoke(), decr(), getFileContent(), getMulti(), getNamespace(), processGetResult(), setMulti(), setNamespace()
Methods inherited from Wei\Base
__call(), __get(), getOption(), setOption()
Properties summary
protected string $table

The cache table name

The cache table name

# 'cache'
protected boolean $checkTable

Whether check if table is exists or not

Whether check if table is exists or not

# true
protected array $checkTableSqls

The SQL to check if table exists

The SQL to check if table exists

# array( 'mysql' => "SHOW TABLES LIKE '%s'", 'sqlite' => "SELECT name FROM sqlite_master WHERE type='table' AND name='%s'", 'pgsql' => "SELECT true FROM pg_tables WHERE tablename = '%s'" )
protected array $createTableSqls

The SQL to create cache table

The SQL to create cache table

# array( 'mysql' => "CREATE TABLE %s (id VARCHAR(255) NOT NULL, value LONGTEXT NOT NULL, expire DATETIME NOT NULL, lastModified DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", 'sqlite' => "CREATE TABLE %s (id VARCHAR(255) NOT NULL, value CLOB NOT NULL, expire DATETIME NOT NULL, lastModified DATETIME NOT NULL, PRIMARY KEY(id))", 'pgsql' => "CREATE TABLE %s (id VARCHAR(255) NOT NULL, value TEXT NOT NULL, expire TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, lastModified TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))", )
Properties inherited from Wei\BaseCache
$namespace
Properties inherited from Wei\Base
$providers, $wei
Magic properties summary
public Wei\Db $db

A database service

Wei Framework API documentation generated by ApiGen