forked from PHPSocialNetwork/phpfastcache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example2.php
41 lines (27 loc) · 897 Bytes
/
example2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/*
* Welcome to Learn Lesson
* This is very Simple PHP Code of Caching
*/
// Require Library
require_once("phpfastcache.php");
// simple Caching with:
$cache = phpFastCache("redis");
if($cache->fallback === true) {
echo " USE BACK UP DRIVER = ".phpFastCache::$config['fallback']." <br>";
} else {
echo ' DRIVER IS GOOD <br>';
}
// Try to get $products from Caching First
// product_page is "identity keyword";
$products = $cache->get("product_page2");
if($products == null) {
$products = "DB QUERIES | FUNCTION_GET_PRODUCTS | ARRAY | STRING | OBJECTS";
// Write products to Cache in 10 minutes with same keyword
$cache->set("product_page2",$products , 2);
echo " --> NO CACHE ---> DB | Func | API RUN FIRST TIME ---> ";
} else {
echo " --> USE CACHE --> SERV 10,000+ Visitors FROM CACHE ---> ";
}
// use your products here or return it;
echo "Products = ".$products;