Issues

ZF-11073: Zend_Cache_Backend_Dba

Description

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 https://github.com/gjerokrsteski/php-dba-cache

I allso can see the "Zend_Cache_Backend_Dba" class at https://github.com/gjerokrsteski/… for inspection.

Best regards, Gjero Krsteski

Comments

Hi Giero,

That's an very interesting idea !

But please note the following:

Greetings

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 https://github.com/gjerokrsteski/…

HI Gjero,

I impemented a dba adapter for ZF2 to see how it works an find issues: https://github.com/marc-mabe/zf2/…

One think i have found is described @ http://bugs.php.net/bug.php?id=54242 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).

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?

??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 @ http://framework.zend.com/svn/framework/… 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 ;)

Changed assignee to Gjero

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.

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: -> php.net: 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

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.

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 ?

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?

Cloned for ZF2 see ZF2-139