AhCache

Description

This is a PHP class to store and cache data as a file. You can use this class without any additonal service on any hoster. It does not require any library, framework or database.
I wrote it to cache data for the website of Swiss public radio (DRS/ SRF) where it was in use for several years.

You can store any data you can handle with the serialize function: integers, strings/ texts, arrays, objects. In other words: 99.9% of all data you can fetch from internet services or database resultsets.

If it is called a cache you need to know, when it is outdated an when you must refresh your cached data.
You can put a TTL (in sec) to your data. Or you can compare the cache with another local file.
Additionally you have methods to see the age of your cache, is it outdated already or not.

If you create data you must be able to cleanup them. This class offers to delete a single cache item, all cached items of an application or all cached items of all applications

GNU GPL v 3.0

The project is hosted on Github: ahcache

Download

Requirements

You can use this class nearly anywhere on each hoster in the world. The requirements are the most simple you can imagine:

  • PHP 7 or 8 (it runs on PHP 5 but I don't support it)
  • a writeable directory; [webroot]/~cache/ by default

Last Updates


  • 2021-10-07: v2.8
    • FIX: remove chdir() in _readCacheItem()
    • ADD reference file to expire a cache item
      • added: getRefFile
      • added: setRefFile
      • update: dump, isExpired, isNewerThanFile, write
      • update cache admin

  • 2021-09-30: v2.7
    • FIX: remove chdir() in _readCacheItem()

  • 2021-09-28: v2.6
    • added a simple admin UI; the cache class got a few new methods
    • update: cleanup() now always deletes expired items
    • update: dump() styles output as table
    • added: getCurrentModule
    • added: deleteModule
    • added: loadCachefile
    • added: removefileDelete
    • added: setCacheId
    • added: setModule







Copyright © 2009-2024 Axel Hahn
project page: GitHub (en)
Axels Webseite (de)
results will be here