$_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.


This way, only the first user of every day will get the 'slow'
treatment.

You can also set up a scheduled 'job', or even a scheduled task on your
desktop that hit the web page at 12:01am if you leave your PC on.  Any
kind of scheduling will do.

That was my solution and for what I needed, it's a little better than
the $_SESSION deal because I may have 20 people access the data once or
twice at various times of the day.  So session might expire and it's a
fairly slow report (well, 30 seconds give or take) and they're
impatient.

-TG

> -----Original Message-----
> From: Vincent DUPONT [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, January 28, 2004 3:49 AM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: [PHP] Cacheing data form PHP script
> 
> 
> Hi all,
>  
> I use a HTML menu that is created from multiple database 
> queries. This is powerfull and very extendable.
> The problem is that the queries have to be executed on every 
> new page or request.
> Moreover, the menu won't change very often for the users.
>  
> So I would like to 'cache' the HTML code that is generated.  
> If one admin add/remove/update one menu, I need to clear the cache.
>  
> At the moment, I store the HTML code to display the menu in 
> the $_SESSION['menu_cache']['menu_id'] var. And this works 
> well! The pages are displayed faster when the menu is in the 
> cache, which is the expected result!
>  
> What is your opinion about this?
> Do you see any other way to 'cache' some content?
>  
> Could I use the $_ENV variable (or any other) to cache the 
> menus accross ALL visitors/users?
>  
> Thank you
>  
> Vincent
> 
> 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to