Jelajahi Sumber

Merge branch 'master' of https://git.97admin.com:433/chendeben/taoqu

chendeben 6 tahun lalu
induk
melakukan
df22230387

+ 15 - 0
App/Api/Controller.php

@@ -57,8 +57,23 @@ abstract class Controller extends \Heanup\Frame\Controller
             $con=new Search();
             $con->main();
         }
+        $this->cache();
         return true;
     }
+    protected function cache(){
+        $key="cache:".md5(json_encode($_REQUEST));
+        $cache=Redis::instance()->get($key);
+        if ($cache){
+            echo $cache;
+            die();
+        }
+    }
+    protected function setCache($content){
+        $key="cache:".md5(json_encode($_REQUEST));
+        Redis::instance()->set($key, $content,3600*3);
+        echo $content;
+        die();
+    }
 
 
     /**

+ 2 - 1
App/Api/Controller/Category.php

@@ -32,7 +32,8 @@ class Category extends Controller
             $request['page'] = $page;
         }
         $url = Site::getData('site_url') . "/tao.php?" . http_build_query($request);
-        echo Dataoke::parse(file_get_contents($url));
+        $content= Dataoke::parse(file_get_contents($url));
+        $this->setCache($content);
     }
 
     protected function after()

+ 2 - 1
App/Api/Controller/Detail.php

@@ -15,7 +15,8 @@ class Detail extends Controller
         $id = $this->getQuery()->intval("id");
         $u = Site::getData("user_tag");
         $url = sprintf(Site::getData('site_url') . "/tao.php?r=l/d&id=%s&u=%s", $id, $u);
-        echo Dataoke::parse(file_get_contents($url));
+        $content= Dataoke::parse(file_get_contents($url));
+        $this->setCache($content);
     }
 
     protected function after()

+ 2 - 2
App/Api/Controller/Index.php

@@ -14,8 +14,8 @@ class Index extends Controller
     protected function main()
     {
         $url = Site::getData('site_url') . "/tao.php?r=index/index";
-        $content = file_get_contents($url);
-        $content = Dataoke::parse($content);
+        $content= Dataoke::parse(file_get_contents($url));
+        $this->setCache($content);
         echo $content;
     }
 }

+ 2 - 1
App/Api/Controller/Pages.php

@@ -20,7 +20,8 @@ class Pages extends Controller
         ];
         $page = $this->getQuery()->string("args_0");
         $url = sprintf(Site::getData('site_url') . "/tao.php?r=%s", $route[$page]);
-        echo Dataoke::parse(file_get_contents($url));
+        $content= Dataoke::parse(file_get_contents($url));
+        $this->setCache($content);
     }
 
 }

+ 2 - 1
App/Api/Controller/Search.php

@@ -30,7 +30,8 @@ class Search extends Controller
         }
 
         $url = Site::getData('site_url') . "/tao.php?".http_build_query($request);
-        echo Dataoke::parse(file_get_contents($url));
+        $content= Dataoke::parse(file_get_contents($url));
+        $this->setCache($content);
     }
 
 }