如何在php中建立内存服务器端缓存? [英] how to build a in-memory server side cache in php?

查看:171
本文介绍了如何在php中建立内存服务器端缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过提供内存中缓存来减少数据库访问量。
我知道我可以使用会话和cookie来获得缓存,但是这仅适用于每个客户端。如果在每个会话中都进行一次相同的查询,则缓存将无用。但是我只想访问数据库一次并对其进行缓存。

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

推荐答案

您可以使用 MemCache (如果已安装)。

You can use MemCache, if installed.

另一个选择是在MySQL中创建一个存储类型为内存。您仍将使用数据库,但是它将更快。但是MemCache确实可以减少数据库的负载,因为您可以将数据缓存在数据库外部,甚至可以在其他服务器上。

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.

这篇关于如何在php中建立内存服务器端缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆