PHPackages                             gjerokrsteski/php-dba-cache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. gjerokrsteski/php-dba-cache

ActiveLibrary[Caching](/categories/caching)

gjerokrsteski/php-dba-cache
===========================

Create a caching with the PHP Database (dbm-style) Abstraction Layer to cache your objects, strings, integers or arrays

v0.2.0(7y ago)18193BSDPHPPHP &gt;=5.4

Since Jan 31Pushed 7y ago2 watchersCompare

[ Source](https://github.com/gjerokrsteski/php-dba-cache)[ Packagist](https://packagist.org/packages/gjerokrsteski/php-dba-cache)[ Docs](http://gjerokrsteski.github.io/php-dba-cache/)[ RSS](/packages/gjerokrsteski-php-dba-cache/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)DependenciesVersions (4)Used By (0)

Introduction
============

[](#introduction)

The php-dba-cache uses the database (dbm-style) abstraction layer to cache/store your PHP objects, strings, integers or arrays. Even instances of SimpleXMLElement can be put to the cache. You don`t have to matter about the size of the cache-file. It depends on the free space of your disk.

[![Build Status](https://camo.githubusercontent.com/8b655e6be5e0d8006e0f7b09d156d5c738c08c22c02b2d295d0bf0c28c704d61/68747470733a2f2f7472617669732d63692e6f72672f676a65726f6b72737465736b692f7068702d6462612d63616368652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/gjerokrsteski/php-dba-cache)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/f50915a9da993f2282e0afb76bda86b6aa655550bc6879e1917d720ede834f74/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f676a65726f6b72737465736b692f7068702d6462612d63616368652f6261646765732f7175616c6974792d73636f72652e706e673f733d30356333356539336234303236353339303139353535653033346139393936383339613363363538)](https://scrutinizer-ci.com/g/gjerokrsteski/php-dba-cache/)[![Dependency Status](https://camo.githubusercontent.com/835a7557b20dd005ea750043cc8f0e9896508f0de69ef1cb6ae7eaad90da13c8/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f7068702f676a65726f6b72737465736b693a7068702d6462612d63616368652f6465762d6d61737465722f62616467652e706e67)](https://www.versioneye.com/php/gjerokrsteski:php-dba-cache/dev-master)

Sample for Oracle Berkeley DB 4 with persistent connection
----------------------------------------------------------

[](#sample-for-oracle-berkeley-db-4-with-persistent-connection)

```
$cache = new Cache(
  '/your/path/to/the/cahe-file/cache.db4', 'db4'
);

$yorObject            = new ObjectYouWantToPutInCache();
$yourObjectIdentifier = 'your:cool:object:identifier';

// check if your object is in the cache.
// you also can ignore it, and let the CacheDba do it for you.
if (true === $cache->has($yourObjectIdentifier)) {
  $cache->delete($yourObjectIdentifier);
}

$cache->put($yourObjectIdentifier, $yorObject);

// than somewhere at your project.
$cache->get($yourObjectIdentifier);

// for the garbage collection
// you can create an cron-job starting once a day.
$sweep = new Sweep($cache);
$sweep->all();

// or clean all objects older than given expiration since now.
$sweep->old();
```

Saving SimpleXMLElement instances into DB 4 with persistent connection
----------------------------------------------------------------------

[](#saving-simplexmlelement-instances-into-db-4-with-persistent-connection)

```
$string = "

 Let us cache
 Joe
 Jane
 Some content here
";

$simplexml = simplexml_load_string(
    $string,
    'SimpleXMLElement',
    LIBXML_NOERROR|LIBXML_NOWARNING|LIBXML_NONET
);

$identifier = md5('simplexml_identifier');

$path = dirname(__FILE__).'/simple-xml-test-cache.db4';
$cache = new Cache($path, 'db4');

$cache->put($identifier, $simplexml);

$getObject = $cache->get($identifier);

error_log(' - PUT IN CACHE : '.print_r($simplexml, true));
error_log(' - GET FROM CACHE : '.print_r($getObject, true));

error_log(' - IS SAME OBJECT : '.
    print_r(($simplexml->asXml() === $getObject->asXml())
            ? 'true' : 'false', true));
```

PHP DBA Cache Monitor
---------------------

[](#php-dba-cache-monitor)

Responsive web-interface that provides a comprehensive, easy to use and of course good looking GUI. It not only gives access to statistical parameters of DBA Cache, it also makes it easier to administer a web-server running DBA by providing comfortable features for optimizing the cache and deleting entries from the cache.

[![PHP DBA cache Monitor 2014](https://camo.githubusercontent.com/f98c6ce35fe5b29606961c9ce7064cb742a2010e80989d9c5fd397ec34968d9f/687474703a2f2f6661726d392e737461746963666c69636b722e636f6d2f383532382f383534373331313435375f396534613763613435642e6a7067 "PHP DBA Cache Monitor")](https://camo.githubusercontent.com/f98c6ce35fe5b29606961c9ce7064cb742a2010e80989d9c5fd397ec34968d9f/687474703a2f2f6661726d392e737461746963666c69636b722e636f6d2f383532382f383534373331313435375f396534613763613435642e6a7067)

Available options
=================

[](#available-options)

Cache

- Open a given dba database
- Insert a new record with a given key (persistently or with a given expiration time)
- Get a record with a given key
- Replace the value of a record with a given key
- Delete the record with a given key
- Return metadata for the given key: expire timestamp &amp; timestamp of last modification time
- Get all keys from cache

Sweep - CacheGarbageCollector (optional)

- Clean all entries
- Clean expired entries
- Flush the cache file
- Optimizes the database file automatically after cleaning process

Installation
============

[](#installation)

"By using the --enable-dba=shared configuration option you can build a dynamic loadable module to enable PHP for basic support of dbm-style databases. You also have to add support for at least one of the following handlers by specifying the --with-XXXX configure switch to your PHP configure line."

More about installation:

DBA handlers
============

[](#dba-handlers)

The behaviour of various aspects for the caching depends on the implementation of yor installed dba-type database. I have tested it with several database-handlers like db4, flatfile, cdb, cdb\_make, gdbm. The cdb &amp; cdb\_make family is the fastest, but you have to create you own garbage-collection-cleaner or you can delete it manually. Take a look at the tests () to better understand how to use the cache.

cdb = Tiny Constant Database - for reading Cdb is "a fast, reliable, lightweight package for creating and reading constant databases. " It is from the author of qmail and can be found at . Since it is constant, we support only reading operations. And since PHP 4.3.0 we support writing (not updating) through the internal cdb library.

cdb\_make = Tiny Constant Database - for writing Since PHP 4.3.0 we support creation of cdb files when the bundled cdb library is used.

db4 = Oracle Berkeley DB 4 - for reading and writing DB4 is Sleepycat Software's DB4. This is available since PHP 4.3.2.

gdbm = GNU Database Manager - for reading and writing Gdbm is the GNU database manager.

flatfile = default dba extension - for reading and writing This is available since PHP 4.3.0 for compatibility with the deprecated dbm extension only and should be avoided. However you may use this where files were created in this format. That happens when configure could not find any external library.

More about requirements:

Nice to know
------------

[](#nice-to-know)

Not all of the DBA-style databases can replace key-value pairs, like the CDB. The CDB database can handle only with fixed key-value pairs. The best and fastest handlers for DBA-style caching are: QDBM, Berkeley DB (DB4), NDBM and least the Flatfile. Most problematic are dbm and ndbm which conflict with many installations. The reason for this is that on several systems these libraries are part of more than one other library. The configuration test only prevents you from configuring malfaunctioning single handlers but not combinations.

Benchmark Test of DBM Brothers
------------------------------

[](#benchmark-test-of-dbm-brothers)

This benchmark test is to calculate processing time (real time) and file size of database. Writing test is to store 1,000,000 records. Reading test is to fetch all of its records. Both of the key and the value of each record are such 8-byte strings as `00000001', `00000002', `00000003'... Tuning parameters of each DBM are set to display its best performance. Platform: Linux 2.4.31 kernel, EXT2 file system, Pentium4 1.7GHz CPU, 1024MB RAM, ThinkPad T42 Compilation: gcc 3.3.2 (using -O3), glibc 2.3.3

Result

```
NAME        DESCRIPTION                             WRITE TIME  READ TIME   FILE SIZE
QDBM        Quick Database Manager 1.8.74           1.89        1.58        55257
NDBM        New Database Manager 5.1                8.07        7.79        814457
SDBM        Substitute Database Manager 1.0.2       11.32       0.00        606720
GDBM        GNU Database Manager 1.8.3              14.01       5.36        82788
TDB         Trivial Database 1.0.6                  9.64        2.22        51056
CDB         Tiny Constant Database 0.75             0.87        0.80        39065
BDB         Berkeley DB 4.4.20                      9.62        5.62        40956
QDBM-BT-ASC B+ tree API of QDBM (ascending order)   2.37        1.78        24304
QDBM-BT-RND B+ tree API of QDBM (at random)         10.90       4.82        15362
BDB-BT-ASC B+ tree API of BDB (ascending order)     3.04        3.06        27520
BDB-BT-RND B+ tree API of BDB (at random)           10.03       4.15        29120

```

Unit of time is seconds. Unit of size is kilo bytes. Read time of SDBM can not be calculated because its database is broken when more than 100000 records.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~525 days

Total

2

Last Release

2870d ago

PHP version history (2 changes)v0.1.0PHP &gt;=5.2

v0.2.0PHP &gt;=5.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/49bd060da17ed9ba742319679babb4cfadd9205faabb139f91f15f01dcffd7e4?d=identicon)[gjerokrsteski](/maintainers/gjerokrsteski)

---

Top Contributors

[![gjerokrsteski](https://avatars.githubusercontent.com/u/503822?v=4)](https://github.com/gjerokrsteski "gjerokrsteski (175 commits)")[![bitdeli-chef](https://avatars.githubusercontent.com/u/3092978?v=4)](https://github.com/bitdeli-chef "bitdeli-chef (1 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

cachecachemanagercachingcaching-libraryoopphpphp56php7php71php72cachestoragedba

### Embed Badge

![Health badge](/badges/gjerokrsteski-php-dba-cache/health.svg)

```
[![Health](https://phpackages.com/badges/gjerokrsteski-php-dba-cache/health.svg)](https://phpackages.com/packages/gjerokrsteski-php-dba-cache)
```

###  Alternatives

[psr/simple-cache

Common interfaces for simple caching

8.1k727.3M2.1k](/packages/psr-simple-cache)[psr/cache

Common interface for caching libraries

5.2k686.9M1.3k](/packages/psr-cache)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[beste/in-memory-cache

A PSR-6 In-Memory cache that can be used as a fallback implementation and/or in tests.

2512.2M6](/packages/beste-in-memory-cache)[alekseykorzun/memcached-wrapper-php

Optimized PHP 5 wrapper for Memcached extension that supports dog-piling, igbinary and local storage

2984.6k1](/packages/alekseykorzun-memcached-wrapper-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
