/filecache

Cache with file system

Primary LanguagePHPMIT LicenseMIT

filecache Build Status

Cache with file system.

Why File Cache?

In cases you don't want to have other dependencies or don't want to waste your RAM.

Features

  • Compression with gzcompress
  • Expiration
  • Multi level cache directories

Installation

composer require ark/filecache

Usage

<?php
use Ark\Filecache\FileCache;

$cache = new FileCache([
    'root' => '/path/to/cache/root', // Cache root
    'ttl' => 0,                    // Time to live
    'compress' => false,             // Compress data with gzcompress or not
    'serialize' => 'json',          // How to serialize data: json, php, raw
]);

$cache->set('key1', 'value1');
$cache->get('key1');

// Set TTL and compression
$cache->set('key2', array('hello', 'world'), array(
    'ttl' => 10,
    'compress' => true
)); 

sleep(11);

$cache->get('key2');

$cache->delete('key1');

$cache->clear(); // clear all caches by removing the root path of the cache