All Projects → rapidwebltd → Rw File Cache

rapidwebltd / Rw File Cache

Licence: lgpl-3.0
🗄️ PHP File-based Caching Library

Projects that are alternatives of or similar to Rw File Cache

Scrapbook
PHP cache library, with adapters for e.g. Memcached, Redis, Couchbase, APC(u), SQL and additional capabilities (e.g. transactions, stampede protection) built on top.
Stars: ✭ 279 (+2690%)
Mutual labels:  cache, caching
Wp Rocket
Performance optimization plugin for WordPress
Stars: ✭ 394 (+3840%)
Mutual labels:  cache, caching
Cache
The Cache component provides an extended PSR-6 implementation for adding cache to your applications.
Stars: ✭ 3,606 (+35960%)
Mutual labels:  cache, caching
salad
Asynchronous Scala Redis Client supporting Sentinel and Redis Cluster
Stars: ✭ 14 (+40%)
Mutual labels:  caching, cache
Libmc
Fast and light-weight memcached client for C++ / #python / #golang #libmc
Stars: ✭ 429 (+4190%)
Mutual labels:  cache, caching
transitory
In-memory cache with high hit rates via LFU eviction for Node and browsers. Supports time-based expiration, automatic loading and metrics.
Stars: ✭ 24 (+140%)
Mutual labels:  caching, cache
Memento
Memento is a development-only tool that caches HTTP calls once they have been executed.
Stars: ✭ 380 (+3700%)
Mutual labels:  cache, caching
Scaffeine
Thin Scala wrapper for Caffeine (https://github.com/ben-manes/caffeine)
Stars: ✭ 195 (+1850%)
Mutual labels:  cache, caching
Cache Service Provider
A Cache Service Provider for Silex, using the doctrine/cache package
Stars: ✭ 23 (+130%)
Mutual labels:  cache, caching
Lada Cache
A Redis based, fully automated and scalable database cache layer for Laravel
Stars: ✭ 424 (+4140%)
Mutual labels:  cache, caching
Ccache.cmake
🚅 Compile faster with Ccache! A Ccache integration for CMake with Xcode support.
Stars: ✭ 24 (+140%)
Mutual labels:  caching, cache
Cached
Rust cache structures and easy function memoization
Stars: ✭ 530 (+5200%)
Mutual labels:  cache, caching
HAProxy-2-RPM-builder
Build latest HAProxy binary with prometheus metrics support
Stars: ✭ 28 (+180%)
Mutual labels:  caching, cache
lambda-cache
Python utility for caching in Lambda Functions
Stars: ✭ 28 (+180%)
Mutual labels:  caching, cache
punic
Punic is a remote cache CLI built for Carthage and Apple .xcframework
Stars: ✭ 25 (+150%)
Mutual labels:  caching, cache
Cachier
Persistent, stale-free, local and cross-machine caching for Python functions.
Stars: ✭ 359 (+3490%)
Mutual labels:  cache, caching
Haproxy
HAProxy Load Balancer's development branch (mirror of git.haproxy.org)
Stars: ✭ 2,463 (+24530%)
Mutual labels:  cache, caching
Simple Spring Memcached
A drop-in library to enable memcached caching in Spring beans via annotations
Stars: ✭ 185 (+1750%)
Mutual labels:  cache, caching
Stackexchange.redis.extensions
Stars: ✭ 419 (+4090%)
Mutual labels:  cache, caching
Bigcache
Efficient cache for gigabytes of data written in Go.
Stars: ✭ 5,304 (+52940%)
Mutual labels:  cache, caching

RW File Cache

Build Status Coverage Status StyleCI Packagist

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

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

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

Usage

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

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.

Option Description Default
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

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

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

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).
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].