×

TP 查询缓存

admin admin 发表于2015-08-05 19:04:02 浏览1841 评论0

抢沙发发表评论

<?php
    function cache_data($sql){
            $SqlDao = M("User");                
            $Key = "SqlCache_".md5($sql.time());        
            $FileData    =    F($Key,"","./cache/");            
            if(empty($FileData)){
                        $data = $SqlDao->query($sql);            
                        $FileData['data'] = $data;            
                        $FileData['expire'] = time()+3000; #缓存5分钟            
                        F($Key,$FileData,"./cache/");        
                        }else{            
                            if($FileData['expire']<time()){                
                                    $data = $SqlDao->query($sql);                
                                    $FileData['data'] = $data;                
                                    $FileData['expire'] = time()+3000; #缓存5分钟                
                                    F($Key,$FileData,"./cache/");            
                                }        
                            }        
                        $FileData = F("mp_wechat_token","","./cache/");            
                        return $FileData;    
                  }?>


分享到:

群贤毕至

访客