2011-02-23 84 views
7

我正在寻找一个系统缓存已经编码的项目(与PHP)查询缓存在PHP MySQL的性能

...我已经寻找了一些缓存解决方案具有像注册和登录系统等功能,但我读过如果使用这些功能登录和发布系统失败。

我实际需要的是存储某些特定DB查询的结果,如果存在缓存,调用结果,如果不生成新缓存,并在x分钟内重新缓存它们。 (结果可以存储在txt等)。

我该怎么做?

顺便说一下,将query_cache_type设置为1不起作用。我正在寻找替代解决方案。

感谢

+1

也许这可能是有用的:http://stackoverflow.com/questions/672029/best-technique-for-caching-results-from-queries-that-c​​hange-infrequently – 2011-02-23 03:15:18

回答

6

参考使用内存缓存的例子:here

基本上你需要缓存查询:

# After: [with memcache] 
    $rSlowQuery = mysql_query_cache($sql); 
    # $rSlowQuery is an array 
    $rows = count($rSlowQuery); 
    for ($i=0;$i<$rows;$i++) { } 
1

你可以试试这个:

$mysqli -> query("/*qc=on*/ SELECT * FROM table"); 
5

减少数据库调用 退房phpFastCache支持WinCache,MemCache,Files,X-Cache,APC Cache。这很简单,适合初学者

PHP缓存类数据库:您的网站有10,000个观众 在线谁,和你的动态页面都送万个同查询 数据库中每个页面加载。使用phpFastCache,您的页面只会向数据库发送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 
    } 
?>