PHP Classes

How to Use a PHP Cache Library That Keeps Track of the History of Cached Values Using the Package Time Travel Cache: Store multiple versions of values in cache files

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2026-04-10 (4 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
timetravelcache 1.0MIT/X Consortium ...7Cache, Data types, PHP 7
Description 

Author

This package can store multiple versions of values in cache files.

It provides a class that can store values for each cache key in arrays.

The class can also keep track of the key values for a given number of versions.

It can also revert the cache key values to their previous versions.

Picture of Dwight José Trujillo Barco
Name: Dwight José Trujillo ... is available for providing paid consulting. Contact Dwight José Trujillo ... .
Classes: 2 packages by
Country: Venezuela Venezuela
Age: 61
All time rank: Not yet ranked
Week rank: Not yet ranked
Innovation award
Innovation award
Nominee: 1x

Instructions

Documentation

?# 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.


  Files folder image Files (14)  
File Role Description
Files folder imageapi (7 files)
Files folder imagedocs (1 file)
Files folder imageexamples (3 files)
Files folder imagesrc (1 file)
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (14)  /  api  
File Role Description
  Accessible without login Plain text file clear.php Example Example script
  Accessible without login Plain text file get.php Example Example script
  Accessible without login Plain text file getByIndex.php Example Example script
  Accessible without login Plain text file history.php Example Example script
  Accessible without login Plain text file prune.php Example Example script
  Accessible without login Plain text file revertToIndex.php Example Example script
  Accessible without login Plain text file set.php Example Example script

  Files folder image Files (14)  /  docs  
File Role Description
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (14)  /  examples  
File Role Description
  Accessible without login HTML file audit-log.html Doc. Documentation
  Accessible without login HTML file dashboard.html Doc. Documentation
  Accessible without login HTML file time-machine.html Doc. Documentation

  Files folder image Files (14)  /  src  
File Role Description
  Plain text file TimeTravelCache.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0