Skip to content

Commit 3cca8f8

Browse files
committed
Merge pull request #188 from Geolim4/final
Merged 4.0-dev to final
2 parents 812bd9d + f941b3c commit 3cca8f8

File tree

1 file changed

+48
-91
lines changed

1 file changed

+48
-91
lines changed

README.md

Lines changed: 48 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -10,116 +10,73 @@ Supported: Redis, Predis, Cookie, Files, MemCache, MemCached, APC, WinCache, X-C
1010

1111
---------------------------
1212
Reduce Database Calls
13+
---------------------------
1314

1415
Your website have 10,000 visitors who are online, and your dynamic page have to send 10,000 same queries to database on every page load.
1516
With phpFastCache, your page only send 1 query to DB, and use the cache to serve 9,999 other visitors.
1617

17-
```php
18-
<?php
19-
/*
20-
* Welcome to Learn Lesson
21-
* This is very Simple PHP Code of Caching
22-
*/
23-
24-
// Require Library
25-
// Keep it Auto or setup it as "files","sqlite","wincache" ,"apc","memcache","memcached", "xcache"
26-
require_once("phpfastcache.php");
27-
phpFastCache::setup("storage","auto");
28-
// phpFastCache::setup("storage","files");
29-
// OR open phpfastcache.php and edit your config value there
30-
31-
// simple Caching with:
32-
$cache = phpFastCache();
33-
// $cache = phpFastCache("redis");
34-
35-
// Try to get $products from Caching First
36-
// product_page is "identity keyword";
37-
$products = $cache->get("product_page");
38-
39-
if($products == null) {
40-
$products = "DB QUERIES | FUNCTION_GET_PRODUCTS | ARRAY | STRING | OBJECTS";
41-
// Write products to Cache in 10 minutes with same keyword
42-
$cache->set("product_page",$products , 600);
43-
}
44-
45-
// use your products here or return it;
46-
echo $products;
47-
```
4818
---------------------------
49-
```php
50-
<?php
51-
52-
/*
53-
* List of function and example
54-
*/
55-
require_once("phpfastcache.php");
56-
$cache = phpFastCache();
57-
58-
// Write into cache
59-
$cache->set("keyword", "data | array | object", 300);
60-
$cache->set("keyword", "data | array | object"); // <-- Non-Expired Objects without Time, until you delete the cache.
61-
62-
// Read from Cache | return "null" or "data"
63-
$data = $cache->get("keyword");
64-
echo $data;
65-
66-
// Temporary disabled phpFastCache
67-
phpFastCache::$disabled = true;
68-
$data = $cache->get("keyword");
69-
echo $data; // ALWAYS RETURN NULL;
70-
71-
// Read object information | value | time from cache
72-
$object = $cache->getInfo("keyword");
73-
print_r($object);
19+
Rich Development API
20+
---------------------------
7421

75-
// Delete from cache
76-
$cache->delete("keyword");
22+
Phpfastcache offers you a lot of usefull APIS:
7723

78-
// Clean up all cache
79-
$cache->clean();
24+
- get() // The getter, obviously
25+
- set() // The setter, for those who missed it
26+
- delete() // For removing a cached thing
27+
- clean() // Allow you to completely empty the cache and restart from the beginning
28+
- touch() // Allow you to extends the lifetime of an entry without altering the value
29+
- increment() // For integer that we can count on
30+
- decrement() // Redundant joke...
31+
- search() // Allow you to perform some search on the cache index
32+
- isExisting() // Check if your cache entry exists, it is the equivalent of isset()
33+
- stats() // Return the cache statistics, useful for checking disk space used by the cache etc.
8034

81-
// Stats
82-
$array = $cache->stats();
83-
print_r($array);
35+
---------------------------
36+
As Fast To Implement As Opening a Beer
37+
---------------------------
8438

85-
// Increase and Decrease Cache value - Return true | false
86-
$cache->increment("keyword", 1);
87-
$cache->decrement("keyword", 1);
8839

89-
// Extend expiring time - Return true | false;
90-
$cache->touch("keyword", 1000);
40+
#### Step 1: Include phpfastcache in your project with composer:
9141

92-
// Check Existing or not - Return true | false;
93-
$cache->isExisting("keyword");
9442

95-
// Get & Set Multiple Items
96-
// Same as above, but input is array();
43+
```bash
44+
composer require phpfastcache/phpfastcache
45+
```
9746

98-
$list = $cache->getMulti(array("key1","key2","key3"));
47+
#### Step 2: Setup your website code to implements phpfastcache bits
48+
```php
49+
use Phpfastcache\core\InstanceManager;
9950

100-
$list = $cache->getInfoMulti(array("key1","key2","key3"));
51+
// Include composer autoloader
52+
require '../vendor/autoload.php';
10153

102-
$cache->setMulti(array("key1","value1", 300),
103-
array("key2","value2", 600),
104-
array("key3","value3", 1800));
54+
$cache = InstanceManager::getInstance();
10555

106-
$cache->deleteMulti(array("key1","key2","key3"));
56+
/**
57+
* Try to get $products from Caching First
58+
* product_page is "identity keyword";
59+
*/
60+
$key = "product_page";
61+
$products = $cache->get($key);
10762

108-
$cache->isExistingMulti(array("key1","key2","key3"));
63+
if (is_null($products)) {
64+
$products = "DB QUERIES | FUNCTION_GET_PRODUCTS | ARRAY | STRING | OBJECTS";
65+
// Write products to Cache in 10 minutes with same keyword
66+
$cache->set($key, $products, 600);
10967

110-
$cache->touchMulti(array(
111-
array("key", 300),
112-
array("key2", 400),
113-
));
68+
echo " --> NO CACHE ---> DB | Func | API RUN FIRST TIME ---> ";
11469

115-
$cache->incrementMulti(array(
116-
array("key", 1),
117-
array("key2", 2),
118-
));
70+
} else {
71+
echo " --> USE CACHE --> SERV 10,000+ Visitors FROM CACHE ---> ";
72+
}
11973

120-
$cache->decrementMulti(array(
121-
array("key", 1),
122-
array("key2", 2),
123-
));
74+
/**
75+
* use your products here or return it;
76+
*/
77+
echo $products;
12478

12579
```
80+
#### Step 3: Enjoy ! Your website is now faster than flash !
81+
82+
For curious developpers, there is a lot of others available examples [here](https://github.com/khoaofgod/phpfastcache/tree/final/examples)

0 commit comments

Comments
 (0)