[PEPr] Comment on Caching::phpfastcache

[email protected] ("Bertrand Mansion") Mon, 13 May 2013 20:47:38 +0100 (BST)
Newsgroups php.pear.dev
Message-ID <[email protected]>
Hi,

I only looked quickly at the code.

I think that there is room for improvements. The 'one class does it all'
concept is bad here because it reduces your code reusability,
extendability, flexibility and creates maintenance problems. It makes it
painful to add a new backend (redis, apcu, tokyotyrant, mongodb, ...) or
modify an existing one.

You could improve it by looking at the current Cache_Lite or Cache
packages, and investigating design patterns like Bridge and maybe Chain of
responsability in case you want to keep the possibility to have multiple
backends.

http://en.wikipedia.org/wiki/Bridge_pattern
http://en.wikipedia.org/wiki/Chain_of_responsibility_pattern

You could allow backends to register themselves as available upon loading.
You seem to have defined your own order of priority for backends, this
should maybe left as a parameter for the user.

You use static functions for set/get. This is also wrong because it doesn't
allow to have more than one cache. You should provide a factory method
instead, maybe a singleton method if necessary. See the Log package, it is
a good example of an API you could use.

In conclusion, your code probably works fine, but it is poor design.

-- 
http://pear.php.net/pepr/pepr-proposal-show.php?id=692