PHPackages                             rothkj1022/php-cache-class - 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. rothkj1022/php-cache-class

ActiveLibrary[Caching](/categories/caching)

rothkj1022/php-cache-class
==========================

A simple file based cache based from Erik Giberti's FileCache class, forked from lodev09/php-cache-class.

2.1.5(2y ago)0861MITPHPPHP ^5.2 || ^7.0 || ^8.0

Since Jun 12Pushed 2y ago1 watchersCompare

[ Source](https://github.com/rothkj1022/php-cache-class)[ Packagist](https://packagist.org/packages/rothkj1022/php-cache-class)[ RSS](/packages/rothkj1022-php-cache-class/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (5)Dependencies (1)Versions (7)Used By (1)

PHP FileCache Class (File base)
===============================

[](#php-filecache-class-file-base)

A simple file based cache based from Erik Giberti's FileCache class. See [here](http://af-design.com/blog/2010/07/30/simple-file-based-caching-in-php/)

Enhanced Features
-----------------

[](#enhanced-features)

- Data is serialized and JSON encoded
- Cache data is encrypted by `mcrypt`
- File Based Cache was explained [here](http://af-design.com/blog/2010/07/30/simple-file-based-caching-in-php/)

Installation
------------

[](#installation)

Run the following command in your command line shell in your php project

```
$ composer require rothkj1022/php-cache-class
```

Done.

You may also edit composer.json manually then perform `composer update`:

```
"require": {
    "rothkj1022/php-cache-class": "^2.1.0"
}

```

Getting started
---------------

[](#getting-started)

### Example usage with composer

[](#example-usage-with-composer)

```
//load composer packages
require('vendor/autoload.php');

//create new instance of the class
use rothkj1022\FileCache;
$cache = new FileCache\FileCache("tmp/");
```

### Example usage without composer

[](#example-usage-without-composer)

```
//require the class
require_once("lib/FileCache.php");

//create new instance of the class
use rothkj1022\FileCache;
$cache = new FileCache\FileCache("tmp/");

//...
```

### Local file source example

[](#local-file-source-example)

```
$cache_key = "client_list";

//see if we can get an existing cache
if (!$clients_data = $cache->get($cache_key)) {
    //nope. Let's get the real one!
    $clients_data = json_decode(file_get_contents("clients.json"));

    //set the cache up!
    $expire = 3600; //1 hour
    $cache->set($cache_key, $clients_data, $expire);
}

var_dump($clients_data);
```

### External http GET request example

[](#external-http-get-request-example)

```
$uri = 'https://raw.githubusercontent.com/bahamas10/css-color-names/master/css-color-names.json';
$remote_data = $cache->file_get_contents($uri);
var_dump($remote_data);
```

Reference
---------

[](#reference)

Code reference for you to get started!

### Properties

[](#properties)

- `protected $root = '/tmp/';` - Value is pre-pended to the cache, should be the full path to the directory.
- `protected $error = null;` - For holding any error messages that may have been raised
- `private $_encryption_key = 'Fil3C@ch33ncryptionK3y'` - Main key used for encryption (you need to set this up inside the class)

### Methods

[](#methods)

#### Public Methods

[](#public-methods)

- `Cache::get($key)` - Reads the data from the cache specified by the cache key
- `Cache::set($key [, $data, $ttl])` - Saves data to the cache. Anything that evaluates to false, null, '', boolean false, 0 will not be saved. `$ttl` Specifies the expiry time
- `Cache::delete($key)` - Deletes the cache specified by the `$key`
- `Cache::get_error()` - Reads and clears the internal error
- `Cache::have_error()` - Can be used to inspect internal error

#### Private Methods

[](#private-methods)

See code to see all private methods used like `Cache::_encrypt($pure_string)` etc.

Changelog
---------

[](#changelog)

### Version 2.1.3

[](#version-213)

- Fixed: Stopped echoing guzzle request errors to screen

### Version 2.1.2

[](#version-212)

- Integrated guzzle for more efficient http get requests

### Version 2.1.1

[](#version-211)

- Changed: Renamed class back to Erik Giberti's original name, FileCache

### Version 2.1.0

[](#version-210)

- Added: Composer integration
- Added: changelog

Credits
-------

[](#credits)

2010 - Authored by Erik Giberti 2011-2014 - Rewritten by Jovanni Lo / [@lodev09](https://twitter.com/lodev09)2018 - Modified by Kevin Roth / [@rothkj1022](https://twitter.com/rothkj1022)

License
-------

[](#license)

Released under the [MIT License](http://opensource.org/licenses/MIT). See [LICENSE](LICENSE) file.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 58.3% 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 ~359 days

Recently: every ~449 days

Total

6

Last Release

1093d ago

PHP version history (2 changes)2.1.0PHP ^5.2 || ^7.0

2.1.4PHP ^5.2 || ^7.0 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3bd167830b02c879a6114bee00b9530318d51241711b8fe6083bfeadde078490?d=identicon)[rothkj1022](/maintainers/rothkj1022)

---

Top Contributors

[![rothkj1022](https://avatars.githubusercontent.com/u/1591839?v=4)](https://github.com/rothkj1022 "rothkj1022 (7 commits)")[![lodev09](https://avatars.githubusercontent.com/u/6686328?v=4)](https://github.com/lodev09 "lodev09 (3 commits)")[![krothapigroup](https://avatars.githubusercontent.com/u/146483151?v=4)](https://github.com/krothapigroup "krothapigroup (2 commits)")

### Embed Badge

![Health badge](/badges/rothkj1022-php-cache-class/health.svg)

```
[![Health](https://phpackages.com/badges/rothkj1022-php-cache-class/health.svg)](https://phpackages.com/packages/rothkj1022-php-cache-class)
```

###  Alternatives

[svix/svix

Svix PHP Library

3.2k722.4k6](/packages/svix-svix)[eliashaeussler/cache-warmup

Composer package to warm up website caches, based on a given XML sitemap

73387.5k5](/packages/eliashaeussler-cache-warmup)[eliashaeussler/typo3-warming

Warming - Warms up Frontend caches based on an XML sitemap. Cache warmup can be triggered via TYPO3 backend or using a console command. Supports multiple languages and custom crawler implementations.

20229.9k](/packages/eliashaeussler-typo3-warming)[biigle/laravel-file-cache

Fetch and cache files from local filesystem, cloud storage or public webservers in Laravel

1130.9k1](/packages/biigle-laravel-file-cache)

PHPackages © 2026

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