Forum Moderators: open

Message Too Old, No Replies

Cache Object & Multiple users

Is cache available to all users?

         

raywood

11:30 pm on Aug 30, 2004 (gmt 0)

10+ Year Member



If I put a dataset in the cache object when the first user requests a page, then does the next user get to access the object and avoid a database query, assuming the cache has not expired?
All the documentation I see says the cache has application scope. So it seems like a great way to tune performance when I'm using several large datasets on a page.
Am I correct? Cache a datset one time and all the other users can get at it?

Xoc

3:45 am on Aug 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You've got it. That's exactly what the cache is good for. If you need session level scoping of the cache object, append the user's session ID to the end of the key name.

raywood

12:23 pm on Aug 31, 2004 (gmt 0)

10+ Year Member



Thanks, Xoc. I thought that was it, but I wasn't sure. So, I can put a big dataset like a product catalog in the cache. Then, depending on the expiration time, All the users all day can search products without any database queries. This sounds perfect for data that doesn't change very often, and is read only for users.
I haven't run across any good examples in any books or websites. If there are any out there I'd appreciate a link.
ray

Xoc

12:28 pm on Aug 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The thing you have to remember is that the expiration time on the cache is the maximum expiration time. If the web server gets under pressure and needs more memory, it can expire the cached item early (depending on it's priority).

If you truly need something around forever, store it in an Application variable. Think of the cache as a thing for optimizing the web server.

raywood

8:29 pm on Aug 31, 2004 (gmt 0)

10+ Year Member



Thanks, Xoc.
The app I'm working on right now is a product catalog. The database is updated once each day. So I think the cache is where I should put a dataset. If I am thinking correctly, people always check to see if the cache object is there before building a page. If it's not there, then they query the database and make a new object. So if the server wipes out the dataset, you just have to build it again with another database query.
That's no problem. It still cuts way down on the number of queries when a lot of users get active.