我正在寻找一个系统来缓存已编码的项目(使用PHP),该项目具有注册和登录系统等功能.
我已经搜索了一些缓存解决方案,但我读到如果我使用这些功能,登录和发布系统将失败.
我真正需要的是存储一些特定数据库查询的结果,如果有缓存,调用结果,如果没有生成新缓存,并在每x分钟重新缓存它们.(结果可以存储在txt等中).
我怎样才能做到这一点?
顺便说一下,将query_cache_type设置为1不起作用.我正在寻找替代解决方案.
谢谢
请参阅使用memcache的示例:此处
基本上你需要缓存查询:
# After: [with memcache]
$rSlowQuery = mysql_query_cache($sql);
# $rSlowQuery is an array
$rows = count($rSlowQuery);
for ($i=0;$i<$rows;$i++) { }
Run Code Online (Sandbox Code Playgroud)
减少数据库调用 查看phpFastCache支持WINCACHE,内存缓存,文件,X-Cache功能,APC缓存.这对初学者来说很简单
PHP缓存类数据库:您的网站有10,000名在线访问者,您的动态页面必须在每次加载页面时向数据库发送10,000个相同的查询.使用phpFastCache,您的页面只向DB发送1个查询,并使用缓存为9,999个其他访问者提供服务.
<?php
// In your config file
include("php_fast_cache.php");
// This is Optional Config only. You can skip these lines.
// phpFastCache support "apc", "memcache", "memcached", "wincache" ,"files", "pdo", "mpdo" and "xcache"
// You don't need to change your code when you change your caching system. Or simple keep it auto
phpFastCache::$storage = "auto";
// End Optionals
// In your Class, Functions, PHP Pages
// try to get from Cache first.
$products = phpFastCache::get("products_page");
if($products == null) {
$products = YOUR DB QUERIES || GET_PRODUCTS_FUNCTION;
// set products in to cache in 600 seconds = 10 minutes
phpFastCache::set("products_page",$products,600);
}
foreach($products as $product) {
// Output Your Contents HERE
}
?>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
20727 次 |
最近记录: |