PHPackages                             raorsa/rw-file-cache - 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. raorsa/rw-file-cache

ActiveLibrary[Caching](/categories/caching)

raorsa/rw-file-cache
====================

RW File Cache is a PHP File-based Caching Library. Its syntax is designed to closely resemble the PHP memcache extension.

1.3(1y ago)0372LGPL-3.0-onlyPHPPHP &gt;=8.2

Since May 13Pushed 1y agoCompare

[ Source](https://github.com/raorsa/RW-File-Cache)[ Packagist](https://packagist.org/packages/raorsa/rw-file-cache)[ Docs](https://github.com/raorsa/RW-File-Cache)[ RSS](/packages/raorsa-rw-file-cache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (2)Versions (8)Used By (2)

RW File Cache
=============

[](#rw-file-cache)

[![Build Status](https://camo.githubusercontent.com/b3765a0dfeb94f206b3364359b913fff2b65397222a00a88948c3b98356a23fe/68747470733a2f2f7472617669732d63692e6f72672f72617069647765626c74642f52572d46696c652d43616368652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/rapidwebltd/RW-File-Cache)[![Coverage Status](https://camo.githubusercontent.com/fcbe402d6f64e202fb23ae5cba7063e0114d7403803abdb6f96d251361388924/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f72617069647765626c74642f52572d46696c652d43616368652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/rapidwebltd/RW-File-Cache?branch=master)[![StyleCI](https://camo.githubusercontent.com/3e2b2d8858728a9a3242e1ccfbe938f1531590c13b9914da413e9a91c07704cb/68747470733a2f2f7374796c6563692e696f2f7265706f732f34363237353733352f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/46275735)[![Packagist](https://camo.githubusercontent.com/544a039db2b80e807ee2be323d52fb83a6c02910118b8e99f73f5c2b262c3d2a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72617069647765626c74642f72772d66696c652d63616368652e737667)](https://camo.githubusercontent.com/544a039db2b80e807ee2be323d52fb83a6c02910118b8e99f73f5c2b262c3d2a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72617069647765626c74642f72772d66696c652d63616368652e737667)

RW File Cache is a PHP File-based Caching Library.

Its syntax is designed to closely resemble the PHP `memcache` extension.

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

[](#installation)

You can easily install with composer. Just run `composer require rapidwebltd/rw-file-cache`.

If you are using Laravel, consider using the [Laravel Cache Driver for RW File Cache](https://github.com/rapidwebltd/RW-File-Cache-Laravel-Cache-Driver) instead.

Usage
-----

[](#usage)

This section will show you how to use RW File Cache. If you have used `memcache` before, this should be pretty familiar.

### Setup &amp; Configuration

[](#setup--configuration)

Before you can do anything with RW File Cache, you must instantiate it and then, if you wish, set some configuration options.

```
require_once "vendor/autoload.php";

$cache = new \rapidweb\RWFileCache\RWFileCache();

$cache->changeConfig(["cacheDirectory" => "/tmp/rwFileCacheStorage/"]);
```

This code creates a new RW File Cache object called `$cache` and then configures it to store its cache files in the `/tmp/rwFileCacheStorage/` directory.

There are several different configuration variables you can override. The table below describes them.

OptionDescriptionDefault`cacheDirectory`The directory in which you wish the cache files to be stored. We recommend you change this to a site-specific directory and ensure it is outside of the web root. You must include a trailing slash.`/tmp/rwFileCacheStorage/``gzipCompression`Whether or not to compress cache files using gzip. Unless you are storing very small values in your cache files, we recommend you leave this enabled.`true``fileExtension`The file extension that will be appended to all your cache files.`cache``unixLoadUpperThreshold`If your server's load is greater than this value, cache files will be returned regardless of whether they have expired. This can be used to prevent cache files being regenerated when server load is high. If you do not wish to use this feature, set this option to `-1`.`4.00`### Setting a cache item

[](#setting-a-cache-item)

Putting something in your file cache is easy. You just need to use the `set` method, as shown below.

```
$cache->set('nursery_rhyme',"Mary had a little lamb", strtotime('+ 1 day'));
```

The first parameter is the cache key, which uniquely references this cache item.

The second parameter is the cache value - what you wish to store in this cache item. This can be a string, integer, array, object or any type of serializable PHP variable.

The third paramter is the expiry time. It can be specified as a UNIX timestamp or as a number of seconds less than 30 days worth. Cache items will expire and not be retrievable when this time is reached.

Note that if you use dots, dashes, underscores or a few other special characters in your cache key, the created cache files will be put into a directory structure. For example, a cache key of `objects.cars.redCar` will be stored in `objects/cars/redCar.cache`. This is useful if you wish to categorise cache files and to prevent too many cache files building up in a single directory.

### Getting a cache item

[](#getting-a-cache-item)

To get a cache item you've previously stored, you need to use the `get` method. An example of how to do this is shown below.

```
$var = $cache->get('nursery_rhyme');
```

The only parameter is the cache key you defined when setting the cache item. You can retrieve any cached variable in this way.

### Other RW File Cache methods

[](#other-rw-file-cache-methods)

The setting and retrieval of cache items are the most important parts of RW File Cache. In fact, the `set` and `get` methods are probably all you will need.

However, the library provides the following more advanced commands if you need them.

- `$cache->delete($key)` - Delete a specific item from the cache.
- `$cache->flush()` - Deletes all items from the cache.
- `$cache->replace($key, $content, $expiry)` - Similar to the `set` method, but will only update a cache item's value if the cache item already exists.
- `$cache->increment($key, $offset)` - Increment a numeric cache item value by the specified offset (or one if the offset is omitted).
- `$cache->decrement($key, $offset)` - Decrements a numeric cache item value by the specified offset (or one if the offset is omitted).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~1 days

Total

7

Last Release

716d ago

PHP version history (2 changes)1.0PHP &gt;=5.2.1

1.2PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/9aafbe65410a72b4a3060ed38675fe8f072f9da964fc8b54bec0238321cf273b?d=identicon)[raorsa](/maintainers/raorsa)

---

Top Contributors

[![Jord-JD](https://avatars.githubusercontent.com/u/650645?v=4)](https://github.com/Jord-JD "Jord-JD (16 commits)")[![raorsa](https://avatars.githubusercontent.com/u/142205270?v=4)](https://github.com/raorsa "raorsa (9 commits)")[![jbrooksuk](https://avatars.githubusercontent.com/u/246103?v=4)](https://github.com/jbrooksuk "jbrooksuk (6 commits)")[![kirsty-gasston](https://avatars.githubusercontent.com/u/12949343?v=4)](https://github.com/kirsty-gasston "kirsty-gasston (2 commits)")

---

Tags

phplibrarycachecachingfile cachecaching library

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/raorsa-rw-file-cache/health.svg)

```
[![Health](https://phpackages.com/badges/raorsa-rw-file-cache/health.svg)](https://phpackages.com/packages/raorsa-rw-file-cache)
```

###  Alternatives

[rapidwebltd/rw-file-cache

RW File Cache is a PHP File-based Caching Library. Its syntax is designed to closely resemble the PHP memcache extension.

15191.3k7](/packages/rapidwebltd-rw-file-cache)[voku/simple-cache

Simple Cache library

322.5M7](/packages/voku-simple-cache)[alekseykorzun/memcached-wrapper-php

Optimized PHP 5 wrapper for Memcached extension that supports dog-piling, igbinary and local storage

2984.6k1](/packages/alekseykorzun-memcached-wrapper-php)

PHPackages © 2026

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