I have a big database, and I get data from there and stored in an array. I am working in this data, but I don't want to get every time this data from the database, I want to cache it, it's enought for me to get each 5 minutes. How could I cache an array?

Thanks for your help.

link|improve this question

You say database, but your tags don't specify one. If it's MySQL - there is SELECT SQL_CACHE mode – Mikhail Mar 11 '11 at 14:39
your question about Php array cache? And in your details you are talking about the database caches .can you give more details? – QueueOverflow Mar 11 '11 at 14:53
feedback

2 Answers

up vote 3 down vote accepted

There are many ways to cache data. Have a look at memcache as a way to store data in server memory between PHP requests.

http://php.net/manual/en/book.memcache.php

link|improve this answer
feedback

Simply you can install APC cache. It uses internal memory of your server.

After you can set array with apc_store('key_name', serialize($array)) and fetch with apc_fetch('key_name')

Also you can define expiration time for caches.

Its very easy and fast.

link|improve this answer
which one is better Alternative PHP Cache and Memcache? – QueueOverflow Mar 11 '11 at 14:42
1  
Memcache can be distributable between servers. But it needs more dependency and it works over TCP port. This means you have extra TCP overhead. APC cannot be distributable but it not uses TCP and not having any dependency. – Osman Üngür Mar 11 '11 at 14:45
It's look very good, could you write here an example which is depending from time.(1 minit cache time). Thanks. – iUngi Mar 11 '11 at 15:24
apc_store(key, value, 60) -- 60 means 1 minute. – Osman Üngür Mar 11 '11 at 15:26
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.