ark/filecache

Cache with file system

v0.1.0 2015-03-22 07:32 UTC

This package is auto-updated.

Last update: 2024-11-13 22:13:17 UTC


README

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