PHP Classes

File: README.md

Recommend this page to a friend!
  Packages of Dwight José Trujillo Barco   Time Travel Cache   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Time Travel Cache
Store multiple versions of values in cache files
Author: By
Last change:
Date: 2 months ago
Size: 2,452 bytes
 

Contents

Class file image Download

?# TimeTravelCache

PHP Version License

TimeTravelCache is a lightweight PHP class that stores a timestamped history of values for each cache key. Unlike traditional caches, you can travel back in time ? retrieve any past version, revert to it, or prune old entries.

? Features

  • ?? Time travel ? access any historical value by index or exact timestamp.
  • ? Revert ? roll back to any previous state (creates a new history entry).
  • ? Pruning ? remove entries older than a given timestamp.
  • ? Null?safe ? distinguishes between missing keys and stored `null` values.
  • ? Zero dependencies ? pure PHP, no extensions required.
  • ? Fast ? O(1) index access, configurable history depth.

? Quick Start

require_once 'src/TimeTravelCache.php';

$cache = new TimeTravelCache(5); // keep 5 entries per key

$cache->set('temperature', 22);
$cache->set('temperature', 24);
$cache->set('temperature', 23);

echo $cache->get('temperature');        // 23
echo $cache->getByIndex('temperature', -2); // 22

$cache->revertToIndex('temperature', 0); // back to 22
echo $cache->get('temperature');        // 22

? Documentation

Full API documentation is available in docs/README.md.

? Demo & Examples

Interactive HTML examples are in the examples/ folder: - dashboard.html ? basic CRUD + history table. - time-machine.html ? index navigation, revert, prune. - audit-log.html ? multi?key audit log with revert buttons.

To run the examples, place the project inside a PHP?capable web server and open the HTML files.

? Project Structure

TimeTravelCache/
??? src/
?   ??? TimeTravelCache.php
??? docs/
?   ??? README.md
??? examples/
?   ??? dashboard.html
?   ??? time-machine.html
?   ??? audit-log.html
??? api/
?   ??? get.php
?   ??? set.php
?   ??? history.php
?   ??? getByIndex.php
?   ??? revertToIndex.php
?   ??? prune.php
?   ??? clear.php
??? README.md
??? LICENSE
??? .gitignore

? License

MIT ? see LICENSE file.