Skip to content

DbCache ​

Type
Class
Namespace
craft\cache
Inherits
craft\cache\DbCache » yii\caching\DbCache » yii\caching\Cache » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable, yii\caching\CacheInterface
Since
3.4.14

View source

Public Properties ​

PropertyDescription
behaviorsyii\base\Behavior – List of behaviors attached to this component.
cacheTablestring – Name of the DB table to store cache content.
dbyii\db\Connection, array, string – The DB connection object or the application component ID of the DB connection.
defaultDurationinteger – Default duration in seconds before a cache entry will expire.
gcProbabilityinteger – The probability (parts per million) that garbage collection (GC) should be performed when storing a piece of data in the cache.
keyPrefixstring – A string prefixed to every cache key so that it is unique globally in the whole cache storage.
serializerarray, null, false – The functions used to serialize and unserialize cached data.

Protected Properties ​

PropertyDescription
isVarbinaryDataField

Public Methods ​

MethodDescription
__call()Calls the named method which is not a class method.
__clone()This method is called after the object is created by cloning an existing one.
__construct()Constructor.
__get()Returns the value of a component property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets the value of a component property.
__unset()Sets a component property to be null.
add()Stores a value identified by a key into cache if the cache does not contain this key.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
behaviors()Returns a list of behaviors that this component should behave as.
buildKey()Builds a normalized cache key from a given key.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
delete()Deletes a value with the specified key from cache.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.
exists()Checks whether a specified key exists in the cache.
flush()Deletes all values from cache.
gc()Removes the expired data values.
get()Retrieves a value from cache with a specified key.
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getOrSet()Method combines both set() and get() methods to retrieve value identified by a $key, or to store the result of $callable execution if there is no cache available for the $key.
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined for this component.
init()Initializes the DbCache component.
madd()Stores multiple items in cache. Each item contains a value identified by a key.
mget()Retrieves multiple values from cache with the specified keys.
mset()Stores multiple items in cache. Each item contains a value identified by a key.
multiAdd()Stores multiple items in cache. Each item contains a value identified by a key.
multiGet()Retrieves multiple values from cache with the specified keys.
multiSet()Stores multiple items in cache. Each item contains a value identified by a key.
off()Detaches an existing event handler from this component.
offsetExists()Returns whether there is a cache entry with a specified key.
offsetGet()Retrieves the value from cache with a specified key.
offsetSet()Stores the value identified by a key into cache.
offsetUnset()Deletes the value with the specified key from cache This method is required by the interface ArrayAccess.
on()Attaches an event handler to an event.
set()Stores a value identified by a key into cache.
trigger()Triggers an event.

Protected Methods ​

MethodDescription
addValue()Stores a value identified by a key into cache if the cache does not contain this key.
addValues()Adds multiple key-value pairs to cache.
deleteValue()Deletes a value with the specified key from cache This is the implementation of the method declared in the parent class.
flushValues()Deletes all values from cache.
getDataFieldName()
getDataFieldValue()
getValue()Retrieves a value from cache with a specified key.
getValues()Retrieves multiple values from cache with the specified keys.
isVarbinaryDataField()
setValue()Stores a value identified by a key in cache.
setValues()Stores multiple key-value pairs in cache.

addValue() ​

Stores a value identified by a key into cache if the cache does not contain this key.

This is the implementation of the method declared in the parent class.

View source

Arguments ​

  • $key (string) – The key identifying the value to be cached
  • $value (string) – The value to be cached. Other types (if you have disabled serializer) cannot be saved.
  • $duration (integer) – The number of seconds in which the cached value will expire. 0 means never expire.

Returns ​

boolean – True if the value is successfully stored into cache, false otherwise

setValue() ​

Stores a value identified by a key in cache.

This is the implementation of the method declared in the parent class.

View source

Arguments ​

  • $key (string) – The key identifying the value to be cached
  • $value (string) – The value to be cached. Other types (if you have disabled serializer) cannot be saved.
  • $duration (integer) – The number of seconds in which the cached value will expire. 0 means never expire.

Returns ​

boolean – True if the value is successfully stored into cache, false otherwise