Skip to content

Commit 302be1d

Browse files
committed
Examples
1 parent bce795d commit 302be1d

File tree

3 files changed

+47
-50
lines changed

3 files changed

+47
-50
lines changed

examples/2.setup.php

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,46 @@
1111
*/
1212

1313
$config = array(
14-
/*
15-
* Default storage
16-
* if you set this storage => "files", then $cache = phpFastCache(); <-- will be files cache
17-
*/
18-
"storage" => "auto", // files, sqlite, auto, apc, wincache, xcache, memcache, memcached,
14+
"storage" => "auto", // auto, files, sqlite, apc, cookie, memcache, memcached, predis, redis, wincache, xcache
15+
"default_chmod" => 0777, // For security, please use 0666 for module and 0644 for cgi.
1916

20-
/*
21-
* Default Path for Cache on HDD
22-
* Use full PATH like /home/username/cache
23-
* Keep it blank "", it will automatic setup for you
24-
*/
25-
"path" => "" , // default path for files
26-
"securityKey" => "", // default will good. It will create a path by PATH/securityKey
2717

2818
/*
29-
* FallBack Driver
30-
* Example, in your code, you use memcached, apc..etc, but when you moved your web hosting
31-
* The new hosting don't have memcached, or apc. What you do? Set fallback that driver to other driver.
19+
* OTHERS
3220
*/
33-
"fallback" => "files",
3421

35-
/*
36-
* .htaccess protect
37-
* default will be true
38-
*/
39-
"htaccess" => true,
22+
// create .htaccess to protect cache folder
23+
// By default the cache folder will try to create itself outside your public_html.
24+
// However an htaccess also created in case.
25+
"htaccess" => true,
26+
27+
// path to cache folder, leave it blank for auto detect
28+
"path" => "",
29+
"securityKey" => "auto", // auto will use domain name, set it to 1 string if you use alias domain name
30+
31+
// MEMCACHE
4032

41-
/*
42-
* Default Memcache Server for all $cache = phpFastCache("memcache");
43-
*/
4433
"memcache" => array(
45-
array("127.0.0.1",11211,1),
34+
array("127.0.0.1",11211,1),
4635
// array("new.host.ip",11211,1),
4736
),
48-
// Default server for redis
49-
"redis" => array("127.0.0.1",6379),
5037

38+
// REDIS
39+
"redis" => array(
40+
"host" => "127.0.0.1",
41+
"port" => "",
42+
"password" => "",
43+
"database" => "",
44+
"timeout" => ""
45+
),
46+
47+
"extensions" => array(),
5148

49+
50+
/*
51+
* Fall back when old driver is not support
52+
*/
53+
"fallback" => "files",
5254
);
5355

5456
phpFastCache::setup($config);
@@ -64,28 +66,17 @@
6466

6567
$config = array(
6668
// ALL OF YOUR CONFIG HERE
69+
// except storage
6770
);
6871

69-
$cache = phpFastCache("cache_method",$config); // this will be $config['storage'] up there;
72+
$cache = phpFastCache("files",$config); // this will be $config['storage'] up there;
7073

7174
// changing config example
7275
$cache->setup("path","new_path");
7376

7477

75-
76-
77-
7878
$cache2 = phpFastCache("memcache"); // this will use memcache
79-
$cache3 = new phpFastCache("apc"); // this will use apc
80-
81-
82-
83-
// something new ???
84-
$products = $cache->my_products;
85-
if($products == null) {
86-
$products = "object | array | function_get_products";
87-
// write to cache
88-
$cache->my_products = array($products, 600);
89-
}
90-
91-
echo $products;
79+
$server = array(
80+
array("127.0.0.1",11211,1),
81+
);
82+
$cache2->setup("memcache",$server);

examples/4.travel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* phpFastCache is free traveling
2525
*/
2626

27-
$cache = new phpFastCache("files");
27+
$cache = phpFastCache("files");
2828

2929
$cache->memcache->keyword = array("data",300);
3030
$cache->sqlite->set("keyword","data",300);

examples/5.master.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
// in your config files
44
include("phpfastcache.php");
55
// auto | memcache | files ...etc. Will be default for $cache = __c();
6-
phpFastCache::$storage = "auto";
6+
phpFastCache::setup("storage","auto");
77

8-
$cache1 = phpFastCache();
9-
$cache1->option("path","/PATH/TO/SOME_WHERE/STORE_FILES/");
8+
$cache1 = phpFastCache("files");
9+
$cache1->setup("path","/PATH/TO/SOME_WHERE/STORE_FILES/");
1010

1111
$cache2 = __c("memcache");
1212
$server = array(array("127.0.0.1",11211,100), array("128.5.1.3",11215,80));
13-
$cache2->option("server", $server);
13+
$cache2->setup("server", $server);
14+
15+
16+
1417

1518
$cache3 = new phpFastCache("apc");
1619

@@ -40,8 +43,9 @@
4043
$data = __c("files")->get("keyword2");
4144
$data = __c()->keyword3;
4245

43-
// Multiple ? No Problem
4446

47+
48+
// Multiple ? No Problem
4549
$list = $cache1->getMulti(array("key1","key2","key3"));
4650
$cache2->setMulti(array("key1","value1", 300),
4751
array("key2","value2", 600),
@@ -51,6 +55,8 @@
5155
$list = $cache1->apc->getMulti(array("key1","key2","key3"));
5256
__c()->memcache->getMulti(array("a","b","c"));
5357

58+
59+
5460
// Others
5561
$cache->delete("keyword");
5662
$cache->increment("keyword", $step = 1);

0 commit comments

Comments
 (0)