RE: [PHP] Cacheing data form PHP script
| From: | daniel at electroteque dot org | Date: | Wed, 28 Jan 2004 23:37:38 +0000 |
| Subject: | RE: [PHP] Cacheing data form PHP script | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-176143@lists.php.net to get a copy of this message | ||
> $_SESSION sounds like a good way to go.. It just means that each user
> will pull the data for the menu at least once.
>
> I've done something similar except it was a rather slow database query,
> followed by a bunch of conditional data parsing. The end result wasn't
> very much data (maybe a page's worth) but took a little while to
> compile so we wanted to cache the data so it was only pulled once per
> day. Here's what I did:
>
> 1. Check cache store in database to see if we have data for today. I
> created a 'cache' table in a database with the following fields:
> CacheID, CacheDate, CacheData, CacheDesc or something like that.
> CacheID - Primary key, unique ID (autonum or SQLServer 'idenity'
> field)
> CacheDate - Date of last stored cache, does it equal today? If
> not, pull new data
> CacheData - Here's the fun part. I collected all the data into
> an array, SERIALIZED the array and stored that into this field. All
> data in one big chunk.
> CacheDesc - Since I have multiple caches..or potentially do.. I
> put a test desc so I can go in using WinSQL or something and know what
> it is. That's for the humans :)
>
> 2. If we have data for today, pull it from the cache. Unserialize
> data, run it through the same output processing function that I use for
> 'fresh' data since it's already in the correct format
>
> 3. If cache isn't present, pull new data, insert/update database,
> display data.
>
>
Seems like a huge headache, maybe store the array in a session is the best
bet, but then yes what if one of the admins goes into manage tool i built
to manage the data on the pulldown menus ? So would you suggest store the
array in a cache table as serialized, then if we update replace the data ,
using REPLACE ?