{"id":15024214,"url":"https://github.com/gjerokrsteski/php-dba-cache","last_synced_at":"2026-03-10T04:33:49.780Z","repository":{"id":62511076,"uuid":"1150164","full_name":"gjerokrsteski/php-dba-cache","owner":"gjerokrsteski","description":"Create a caching with the Database (dbm-style) Abstraction Layer to cache your objects, strings, integers or arrays.","archived":false,"fork":false,"pushed_at":"2018-07-05T10:16:54.000Z","size":543,"stargazers_count":18,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-14T09:48:38.798Z","etag":null,"topics":["cache","cachemanager","caching","caching-library","oop","php","php56","php7","php71","php72"],"latest_commit_sha":null,"homepage":"http://gjerokrsteski.github.com/php-dba-cache/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gjerokrsteski.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-12-08T16:24:28.000Z","updated_at":"2022-09-22T00:40:15.000Z","dependencies_parsed_at":"2022-11-02T13:01:48.170Z","dependency_job_id":null,"html_url":"https://github.com/gjerokrsteski/php-dba-cache","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/gjerokrsteski/php-dba-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gjerokrsteski%2Fphp-dba-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gjerokrsteski%2Fphp-dba-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gjerokrsteski%2Fphp-dba-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gjerokrsteski%2Fphp-dba-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gjerokrsteski","download_url":"https://codeload.github.com/gjerokrsteski/php-dba-cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gjerokrsteski%2Fphp-dba-cache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30324444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T01:36:58.598Z","status":"online","status_checked_at":"2026-03-10T02:00:06.579Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","cachemanager","caching","caching-library","oop","php","php56","php7","php71","php72"],"created_at":"2024-09-24T19:59:58.203Z","updated_at":"2026-03-10T04:33:49.757Z","avatar_url":"https://github.com/gjerokrsteski.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Introduction\n============\n\nThe php-dba-cache uses the database (dbm-style) abstraction layer to cache/store your PHP objects, \nstrings, integers or arrays. Even instances of SimpleXMLElement can be put to the cache. You don`t\nhave to matter about the size of the cache-file. It depends on the free space of your disk.\n\n[![Build Status](https://travis-ci.org/gjerokrsteski/php-dba-cache.png?branch=master)](https://travis-ci.org/gjerokrsteski/php-dba-cache)\n[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/gjerokrsteski/php-dba-cache/badges/quality-score.png?s=05c35e93b4026539019555e034a9996839a3c658)](https://scrutinizer-ci.com/g/gjerokrsteski/php-dba-cache/)\n[![Dependency Status](https://www.versioneye.com/php/gjerokrsteski:php-dba-cache/dev-master/badge.png)](https://www.versioneye.com/php/gjerokrsteski:php-dba-cache/dev-master)\n\nSample for Oracle Berkeley DB 4 with persistent connection\n----------------------------------------------------------\n\n```php\n$cache = new Cache(\n  '/your/path/to/the/cahe-file/cache.db4', 'db4'\n);\n\n$yorObject            = new ObjectYouWantToPutInCache();\n$yourObjectIdentifier = 'your:cool:object:identifier';\n\n// check if your object is in the cache.\n// you also can ignore it, and let the CacheDba do it for you.\nif (true === $cache-\u003ehas($yourObjectIdentifier)) {\n  $cache-\u003edelete($yourObjectIdentifier);\n}\n\n$cache-\u003eput($yourObjectIdentifier, $yorObject);\n\n// than somewhere at your project.\n$cache-\u003eget($yourObjectIdentifier);\n\n// for the garbage collection \n// you can create an cron-job starting once a day.\n$sweep = new Sweep($cache);\n$sweep-\u003eall();\n\n// or clean all objects older than given expiration since now.\n$sweep-\u003eold();\n```\n\nSaving SimpleXMLElement instances into DB 4 with persistent connection\n----------------------------------------------------------------------\n\n```php\n$string = \"\u003c?xml version='1.0'?\u003e\n\u003cdocument\u003e\n \u003ctitle\u003eLet us cache\u003c/title\u003e\n \u003cfrom\u003eJoe\u003c/from\u003e\n \u003cto\u003eJane\u003c/to\u003e\n \u003cbody\u003eSome content here\u003c/body\u003e\n\u003c/document\u003e\";\n\n$simplexml = simplexml_load_string(\n    $string,\n    'SimpleXMLElement',\n    LIBXML_NOERROR|LIBXML_NOWARNING|LIBXML_NONET\n);\n\n$identifier = md5('simplexml_identifier');\n\n$path = dirname(__FILE__).'/simple-xml-test-cache.db4';\n$cache = new Cache($path, 'db4');\n\n$cache-\u003eput($identifier, $simplexml);\n\n$getObject = $cache-\u003eget($identifier);\n\nerror_log(' - PUT IN CACHE : '.print_r($simplexml, true));\nerror_log(' - GET FROM CACHE : '.print_r($getObject, true));\n\nerror_log(' - IS SAME OBJECT : '.\n    print_r(($simplexml-\u003easXml() === $getObject-\u003easXml())\n            ? 'true' : 'false', true));\n```\n\nPHP DBA Cache Monitor\n---------------------\nResponsive web-interface that provides a comprehensive, easy to use and of course good looking GUI. It not only gives \naccess to statistical parameters of DBA Cache, it also makes it easier to administer a web-server running DBA by \nproviding comfortable features for optimizing the cache and deleting entries from the cache.\n \n ![PHP DBA cache Monitor 2014](http://farm9.staticflickr.com/8528/8547311457_9e4a7ca45d.jpg \"PHP DBA Cache Monitor\")\n\n\n\nAvailable options\n===========================\n\nCache\n- Open a given dba database\n- Insert a new record with a given key (persistently or with a given expiration time)\n- Get a record with a given key\n- Replace the value of a record with a given key\n- Delete the record with a given key\n- Return metadata for the given key: expire timestamp \u0026 timestamp of last modification time\n- Get all keys from cache\n    \nSweep - CacheGarbageCollector (optional)\n- Clean all entries\n- Clean expired entries\n- Flush the cache file\n- Optimizes the database file automatically after cleaning process\n\n\nInstallation\n============\n\n\"By using the --enable-dba=shared configuration option you can build a dynamic loadable module\nto enable PHP for basic support of dbm-style databases. You also have to add support for at\nleast one of the following handlers by specifying the --with-XXXX configure switch\nto your PHP configure line.\"\n    \nMore about installation: http://www.php.net/manual/en/dba.installation.php\n\n\nDBA handlers\n============\n\nThe behaviour of various aspects for the caching depends on the implementation of yor\ninstalled dba-type database. I have tested it with several database-handlers like db4, flatfile,\ncdb, cdb_make, gdbm. The cdb \u0026 cdb_make family is the fastest, but you have to create\nyou own garbage-collection-cleaner or you can delete it manually. Take a look at the tests\n(https://github.com/gjerokrsteski/php-dba-cache/tree/master/tests) to better understand\nhow to use the cache.\n\ncdb = Tiny Constant Database - for reading\nCdb is \"a fast, reliable, lightweight package for creating and reading constant databases.\n\" It is from the author of qmail and can be found at http://cr.yp.to/cdb.html. Since it is\nconstant, we support only reading operations. And since PHP 4.3.0 we support writing\n(not updating) through the internal cdb library.\n\ncdb_make = Tiny Constant Database - for writing\nSince PHP 4.3.0 we support creation of cdb files when the bundled cdb library is used.\n\ndb4 = Oracle Berkeley DB 4 - for reading and writing\nDB4 is Sleepycat Software's DB4. This is available since PHP 4.3.2.\n\ngdbm = GNU Database Manager - for reading and writing\nGdbm is the GNU database manager.\n\nflatfile = default dba extension - for reading and writing\nThis is available since PHP 4.3.0 for compatibility with the deprecated dbm extension only\nand should be avoided. However you may use this where files were created in this format.\nThat happens when configure could not find any external library.\n    \nMore about requirements: http://www.php.net/manual/en/dba.requirements.php\n\nNice to know\n------------\n\nNot all of the DBA-style databases can replace key-value pairs, like the CDB. The CDB database\ncan handle only with fixed key-value pairs. The best and fastest handlers for DBA-style caching\nare: QDBM, Berkeley DB (DB4), NDBM and least the Flatfile.\nMost problematic are dbm and ndbm which conflict with many installations. The reason for this is\nthat on several systems these libraries are part of more than one other library. The configuration\ntest only prevents you from configuring malfaunctioning single handlers but not combinations.\n\nBenchmark Test of DBM Brothers\n------------------------------\n\nThis benchmark test is to calculate processing time (real time)\nand file size of database. Writing test is to store 1,000,000 records. Reading test is\nto fetch all of its records. Both of the key and the value of each record are such 8-byte\nstrings as `00000001', `00000002', `00000003'... Tuning parameters of each DBM are set to\ndisplay its best performance. Platform: Linux 2.4.31 kernel, EXT2 file system,\nPentium4 1.7GHz CPU, 1024MB RAM, ThinkPad T42 Compilation: gcc 3.3.2 (using -O3), glibc 2.3.3\n\nResult\n```cli\nNAME        DESCRIPTION                             WRITE TIME  READ TIME   FILE SIZE\nQDBM        Quick Database Manager 1.8.74           1.89        1.58        55257\nNDBM        New Database Manager 5.1                8.07        7.79        814457\nSDBM        Substitute Database Manager 1.0.2       11.32       0.00        606720\nGDBM        GNU Database Manager 1.8.3              14.01       5.36        82788\nTDB         Trivial Database 1.0.6                  9.64        2.22        51056\nCDB         Tiny Constant Database 0.75             0.87        0.80        39065\nBDB         Berkeley DB 4.4.20                      9.62        5.62        40956\nQDBM-BT-ASC B+ tree API of QDBM (ascending order)   2.37        1.78        24304\nQDBM-BT-RND B+ tree API of QDBM (at random)         10.90       4.82        15362\nBDB-BT-ASC B+ tree API of BDB (ascending order)     3.04        3.06        27520\nBDB-BT-RND B+ tree API of BDB (at random)           10.03       4.15        29120\n```\n\nUnit of time is seconds. Unit of size is kilo bytes. Read time of SDBM can not be calculated\nbecause its database is broken when more than 100000 records.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgjerokrsteski%2Fphp-dba-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgjerokrsteski%2Fphp-dba-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgjerokrsteski%2Fphp-dba-cache/lists"}