ZF-11073: Zend_Cache_Backend_Dba

Issue Type: New Feature Created: 2011-02-14T08:06:17.000+0000 Last Updated: 2012-05-07T07:15:34.000+0000 Status: Open Fix version(s): Reporter: Gjero Krsteski (gjerokrsteski) Assignee: Gjero Krsteski (gjerokrsteski) Tags: - Zend_Cache

Related issues: - ZF2-139



Based on php-dba-cache a have writen a "Zend_Cache_Backend_Dba" class. The php-dba-cache uses the database (dbm-style) abstraction layer to cache your objects, strings, integers or arrays. Even instances of SimpleXMLElement can be puted to the cache. I just wrote the Class "Zend_Cache_Backend_Dba" for my company, and it works fine. More information about php-dba-cache you can find at

I allso can see the "Zend_Cache_Backend_Dba" class at… for inspection.

Best regards, Gjero Krsteski


Posted by Marc Bennewitz (private) (mabe) on 2011-03-02T12:30:11.000+0000

Hi Giero,

That's an very interesting idea !

But please note the following:


Posted by Gjero Krsteski (gjerokrsteski) on 2011-03-03T01:52:53.000+0000

Hi Marc,

thanks for the answer. I already sent the CLA by fax and e-mail. See here, i just wrote an dba-backend-cache…

Posted by Marc Bennewitz (private) (mabe) on 2011-03-25T17:39:45.000+0000

HI Gjero,

I impemented a dba adapter for ZF2 to see how it works an find issues:…

One think i have found is described @ But I can't test all available handlers :( It would be nice if you can could take a look into it and run some more tests with different handlers.

Feel free to backport this version back to ZF1 (without the Cache*-Classes).

Posted by Gjero Krsteski (gjerokrsteski) on 2011-04-01T09:10:00.000+0000

Hi Marc,

thanks for the report. In the next two weeks i will backport your fix of the Bug #54242. There is something you have to know about the DBA-style databases, like not all of the databases can replace key-value pairs, like the CDB. The CDB database can handle onlly with fixed key-vaue pairs. The best and fastest handlers for DBA-style caching are: QDBM, Berkeley DB (DB4), NDBM and least the Flatfile. Why you are trying to re-insert instead of replace the value?

p.s. can you send me the url tho the ZF1 SVN-branch for the backport?

Posted by Marc Bennewitz (private) (mabe) on 2011-04-02T15:51:04.000+0000

??Why you are trying to re-insert instead of replace the value???

dba_insert: If this key already exist in the database, this function will fail. dba_replace: replaces or inserts the entry

Therefor the adapter works as follows: setItem: -> dba_replace addItem: -> dba_insert + workaround for Bug #54242 replaceItem: -> dba_exists + dba_replace

I don't have a backport for ZF1, yet. For now I don't have enough time to implement new features to ZF1 :( If you have SVN-Access you can create a branch @… or create a clean backport on github that can be simply added as one backend file to ZF1.

I read your implementation for ZF1 on github but this requires 3 more classes which are not needed for ZF. Additionally serialization is done on frontend and the backend have to handle strings only. You could store the time within that string using the pack function ;)

Posted by Marc Bennewitz (private) (mabe) on 2011-04-02T15:54:15.000+0000

Changed assignee to Gjero

Posted by Gjero Krsteski (gjerokrsteski) on 2011-04-21T04:23:25.000+0000

You can find the backport on github. I just keep the additional serialization, because i have some additional data, which is important for the caching. Please give me an review.

Posted by Marc Bennewitz (private) (mabe) on 2011-05-03T21:19:00.000+0000

Some small Notices/Questions:

  1. Using constants for mode doesn't help to note which modes are available and how they should use. -> You can set the default mode directly option directly and take a link to php documentation
  2. Using constants for handlers doesn't show all available handlers. -> I would prefer same as on modes
  3. If DB-Faile doesn't exist you create it on __construct and _retrieveDbaConnection (fopen) -> Why is this needed? This should be solved by mode.
  4. On _put you test if the key exists and calls replace or update but dba_replace replaces or inserts the already with one call: -> dba_replace() replaces or inserts the entry described with key and value into the database specified by handle.
  5. Your "test"-Implementation doesn't return mtime if item exist
  6. Why a simple serialize/unserialize isn't enough ?
  7. Missing UnitTests

Posted by Gjero Krsteski (gjerokrsteski) on 2011-09-08T19:10:40.000+0000

Hi Marc,

Thank you for your comment. I've implemented all your improvements. Check it out on github, and please give me a new recognition.

Posted by Marc Bennewitz (private) (mabe) on 2011-09-09T17:29:28.000+0000

Hi Gjero,

Thank you for your work. I have looked into it and the most looks great but two points from above I'm missing:

  1. Your "test"-Implementation doesn't return mtime if item exist

         public function test($id)
             return ((NULL === $this->_dba) ? false : true);
         protected function _has($identifier)
             return dba_exists($identifier, $this->_dba);

... but you have to return a boolean false if the item doesn't exist and the last modification time of the item else.

  1. Why a simple serialize/unserialize isn't enough ?

Posted by Gjero Krsteski (gjerokrsteski) on 2011-09-10T14:59:08.000+0000

Hi Marc,

thank you for the recognition.

to 5.) I implemented it as you wrote. see it on github. to 6.) A simple serialize/unserialize isn't enough, because I made the experience that a lot of people use ZF1 only as library and put any type of data into the cache. By this implementation you can use it in your ZF1-application and handle with strings, and on the other hand you can use it as library and put any types of data into the cache.

p.s. which is the official ZF1 repository on github?

Posted by Marc Bennewitz (private) (mabe) on 2012-01-09T20:30:27.000+0000

Cloned for ZF2 see ZF2-139

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.