2

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.

2
  • You say database, but your tags don't specify one. If it's MySQL - there is SELECT SQL_CACHE mode Commented Mar 11, 2011 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? Commented Mar 11, 2011 at 14:53

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

2

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.

4 Comments

which one is better Alternative PHP Cache and Memcache?
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.
It's look very good, could you write here an example which is depending from time.(1 minit cache time). Thanks.
apc_store(key, value, 60) -- 60 means 1 minute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.