cachedependency dependency based on the primary cache provider

  1. Requirements
  2. Usage
  3. Resources

Using cache dependencies enables you to be in control of your cached data. Yii provides several dependency methods such as database, file and globalState.

They all work fine but when I use memcached as caching provider, I do not want Yii to check dependencies located on the hard drive everytime Yii::app()->cache->get() is called, that is why I created a new dependency based on the current caching provider.

Requirements

Yii 1.0 or above

Usage

Everytime Yii checks dependencies for changes it performs get(...) on the default caching provider. CacheDependency uses a prefix 'cacheDependency-$dependencyName' to make sure it will not conflict with other cached keys.

if (!($data = Yii::app()->cache->get('key'))) {
    $data = new Model();
    Yii::app()->cache->set(
        'key',
        $data,
        new CacheDependency('myDependency')
    );
}

In this case the dependency will be set on the cache key 'cacheDependency-myDependency'. When the cache needs to be reset, simply set the dependency value to a new value.

Yii::app()->cache->set(CacheDependency::buildCacheId('myDependency'), time());

Resources

1 0
4 followers
445 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Caching
Developed by: Tijnos
Created on: Feb 14, 2012
Last updated: 6 years ago

Downloads

show all

Related Extensions