Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to build a in-memory server side cache in php?

I am trying to reduce the amount of database access by providing a in memory cache. I understand that I can get a cache by using session and cookies, however this only works on a per client basis. if the same query is made once in every session, then the cache will be useless. But I only want to access the database once and have it cached.

Is there a way to make create a cache in memory that can be accessed by the server side script? I don't want to store the cache data in a file ..

like image 349
y62wang Avatar asked Oct 13 '11 17:10

y62wang


2 Answers

You can use MemCache, if installed.

Another option is creating a table in MySQL with storage type MEMORY. You will still use the database, but it will be quite a lot faster. But MemCache will really cut the load on the database, because you can cache the data outside the database, even on a different server.

like image 148
GolezTrol Avatar answered Oct 12 '22 09:10

GolezTrol


On a shared hosting space you may not have memcache available. Check APC in that case. Memcache really rocks if you're running on multiple machines. If you're running your site on a single web server APC will do the same job (with lower overhead).

like image 31
rodneyrehm Avatar answered Oct 12 '22 09:10

rodneyrehm