flushable 3

Yii dependency that allows to flush records from the cache


Written in PHP by 2 contributors


Need Support?

we offer maintenance, support and development services for all our open source projects.

Contact Us


This dependency can be used to flush an item from the cache. It allows you to invalidate any cached item like a cached ActiveRecord, a DAO query result, a cached fragment or a cached page.


Import the class file

Either add this line on top of every class file where you want to use it:


or add ext.flushable.FlushableDependency right to the import section of your main.php configuration file.

How to use the dependency

When you create the dependency you have to provide a unique $id wich identifies your cached content.

$dependency = new FlushableDependency('myKey');

Now you can use it for data, fragment or page caching.

If you want to cache some ActiveRecord or DAO result the $id is usually the primary key. In this case you should add the model name to avoid conflicts among different cached model classes:

// Cache a ActiveRecord
$dependency = new FlushableDependency($id,'Post');
$post = Post::model()->cache(3600,$dependency)->findByPk($id);

How to flush a content from cache

Whenever you want to invalidate the cached data you can now call:


If you used the dependency for data caching and added a model name you must provide the same name again:


You could put this into the afterSave() method of your active record (change $id to $this->id) or just call it manually whenever you update the record.

You can also add an $expire parameter to the flushItem() call. It will specify how long the information about the change should be kept in the cache. So obviously this should be more than the longest time which you cache your content. The default is 3600.

How it works

Whenever an item is cached with this dependency it scans the cache for another key. This key is unique per cached item and composed from the two parameters you pass along to the constructor. This other cache value basically indicates 'The item has expired!'. So if no such key is found, the item in the cache is still valid.

With a call to flushItem() you will create such an expiration entry in the cache for the cached item. So when the dependency is evaluated the next time it will find something now and the cached content will no longer be seen as valid.


Release 1.1.2 (IMPORTANT: This update requires to flush your cache!)

  • Changed dependency keys to work flawlessly with file caches (Thanks yiqing-95).

Release 1.1.1

  • Changed dependency value from time() to microtime() to fix timing issues in some scenarios

Release 1.1.0

  • Refactored class interface

Release 1.0.1

  • Initial release

43 other PHP projects

phpwkhtmltopdfPHP 716

A slim PHP wrapper around wkhtmltopdf with an easy to use and clean OOP interface

php-pdftkPHP 213

A PDF conversion and form utility based on pdftk

yii2-localeurlsPHP 189

Automatic locale/language management for URLs

YiiRedisPHP 131

A set of wrappers for different data types in redis

yiipasswordPHP 81

Password strategies for Yii

yii2-dockerizedPHP 64

A template for docker based Yii 2 applications

YiiSolrPHP 50

A wrapper for the pecl solr library that provides common Yii constructs, such as models, data providers etc

php-shellcommandPHP 48

A simple object oriented interface to execute shell commands in PHP

Yii-Docs-GeneratorPHP 47

Generates HTML documentation for Yii applications

YiiGitPHP 36

A git wrapper for Yii, allows access to all git commands programatically

YiiElasticSearchPHP 32

Elastic Search client for Yii

YiiCurlPHP 30

A curl library for Yii

YiiStateMachinePHP 28

A state machine behavior for Yii

yii2-streamlogPHP 19

A Yii 2 log target for streams in URL format

oauth2yiiPHP 18

An OAuth2 client / server extension for the Yii framework

restyiiPHP 16

A RESTful extension for Yii.

packagecompressorPHP 16

A Javascript/CSS compressor based on Yii's package system

localeurlsPHP 12

Automatic locale/language management for URLs

php-excel-readerPHP 12

It reads the binary format of XLS files directly and can return values and formats from any cell. This project is the fork of http://code.google.com/p/php-excel-reader/ that, apparently, is no longer maintained.

pdfablePHP 10

A Yii extension to create PDFs with PHPWkHtmlToPdf/wkhtmltopdf

yii-api-vimPHP 8

Yii API manual plugin for VIM

yii2-excel-messagePHP 7

Translate messages via Excel files

xcrudcontrollerPHP 7

A base class to quickly build customized CRUD interfaces.

yii2-bs3activeformPHP 7

A Bootstrap 3 enhanced ActiveForm for Yii 2

php-tmpfilePHP 6

A convenience class for temporary files

handlebarsphpPHP 6

Transpiles handlebars templates into native PHP templates

Yii-Package-ManagerPHP 6

A package manager for Yii

php-orientdbPHP 5

A fast PHP driver for the OrientDB binary protocol.

yii2-apidoc-vimPHP 5

Yii2 apidoc as Vim helpfiles

translatablePHP 4

Transparent attribute translation for ActiveRecords

YiiUsersPHP 4

User management for Yii

Yii-Resource-ManagerPHP 3

Helpers to allow Yii to interact with resources (files) of different types

bs3activeformPHP 2

A lightweight utility to render Bootstrap 3 forms in Yii

AccessRestrictablePHP 2

A Yii ActiveRecordBehavior that automatically applies conditions for access restriction to every query.

YiiEmailerPHP 2

Emailing functions for Yii

hybridauthmanagerPHP 1

An AuthManager for Yii that stores the hierarchy in a flat PHP file and the assignments in DB

defaultpersisterPHP 1

Yii extension to save and restore model values in user session.

YiiYaaPHP 1

YAA is an additional abstraction layer for Yii that aggregates a number of child models into a clean single model that is easy to cache

YiiLinkablePHP 1

A simple extension for Yii allowing easy and consistent access to model URLs and appropriate anchor text.


simple useless twitter client


An alternative Yii2 application template for purists


Work with PHP files in Active Record way


Yii extension to create URLs that allow to return to a page by storing its GET Parameters on a stack.