info about link
: Javascript : PHP Index : MySQL :
database array caching class
: Source : : Explanation : : Example : : Todo : : Feedback :

Why this script

I often find myself in a position where, for example, i want to fill drop-down boxes with data from the database. Instead of having to query the database each time i want to display the dropdownbox, i wanted an easy way of retrieving it through a caching-mechanism.

What this script can do

It provides an easy interface for:
  • retrieving arrays (from the cache), by means of a key
  • caching the new data when it changes (using the same key)
  • storing the query that is responsible for selecting the data in a structured way
  • testing whether a particular piece of the array exists
All methods are static, so you won't even need to create an object of the class.
This package comes with support for mysql and postgresql. In theory, this class can work with any kind of database however and adding support is relatively easy.

What this script can not do

Although it creates a new cache-file when none exists, it doesn't automatically update the cache file. In other words, you won't be able to set a Time To Live (TTL).
This is a design choice to keep things as fast as possible. The idea is that you update the class yourself whenever you do an INSERT, DELETE or UPDATE query in a database table that holds information you want cached.
If you still want the cache-file to expire you could always write a little script and run it in a cron-job. Simply deleting a cache-file will automatically result in an updated version at the time the data is needed again.

How to use

Although you will find a lot of code in the examples, let me begin by explaining it requires very little code to create and use a cached array. The only thing you will need to do is create a file with a database query in it, for each array that you want to cache. That's it!

I've created a demonstration that be download as a zip-file: dbarray_demo.zip. Simply download it and put it somewhere on your webserver. It contains a configuration page as well that will help you set up the demonstration.
And, of course, the example page contains a lot of usefull examples of how to use it

=[Disclaimer]=     © 2005-2012 Excudo.net