PHPackages                             mikehaertl/flushable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. mikehaertl/flushable

ActiveYii-extension[Caching](/categories/caching)

mikehaertl/flushable
====================

Yii dependency that allows to flush records from the cache

1.1.2(12y ago)37.1k2MITPHPPHP &gt;=5.0.0

Since Mar 29Pushed 12y ago1 watchersCompare

[ Source](https://github.com/mikehaertl/flushable)[ Packagist](https://packagist.org/packages/mikehaertl/flushable)[ Docs](https://github.com/mikehaertl/flushable)[ RSS](/packages/mikehaertl-flushable/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (3)Used By (0)

Flushable
=========

[](#flushable)

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.

\##Usage

### Import the class file

[](#import-the-class-file)

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

```
Yii::import('ext.flushable.FlushableDependency');
```

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

### How to use the dependency

[](#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

[](#how-to-flush-a-content-from-cache)

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

```
FlushableDependency::flushItem('myKey');
```

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

```
FlushableDependency::flushItem($id,'Post');
```

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
------------

[](#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.

Changelog
---------

[](#changelog)

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

[](#release-112-important-this-update-requires-to-flush-your-cache)

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

### Release 1.1.1

[](#release-111)

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

### Release 1.1.0

[](#release-110)

- Refactored class interface

### Release 1.0.1

[](#release-101)

- Initial release

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~292 days

Total

2

Last Release

4541d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ed4cc6f6e2a51bf286f02ad0def4ee6736be32aea75bfdcd43047696cec56869?d=identicon)[mike](/maintainers/mike)

---

Top Contributors

[![mikehaertl](https://avatars.githubusercontent.com/u/675062?v=4)](https://github.com/mikehaertl "mikehaertl (3 commits)")

---

Tags

cacheyiiflush

### Embed Badge

![Health badge](/badges/mikehaertl-flushable/health.svg)

```
[![Health](https://phpackages.com/badges/mikehaertl-flushable/health.svg)](https://phpackages.com/packages/mikehaertl-flushable)
```

###  Alternatives

[cache/void-adapter

A PSR-6 cache implementation using Void. This implementation supports tags

183.0M45](/packages/cache-void-adapter)[spekkionu/assetcachebuster

Prefixes asset urls with a unique hash which will allow invalidation of asset files cached by the browser.

3243.4k](/packages/spekkionu-assetcachebuster)[ihor/cachalot

Cache a lot in a proper way (APC, XCache, Memcached, Redis, Couchbase)

2528.3k](/packages/ihor-cachalot)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
