Skip to content

Commit 8ccdb78

Browse files
committed
Merge pull request #260 from khoaofgod/final
Cookie limited
2 parents 68f0d46 + 8cb1cf6 commit 8ccdb78

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

examples/cookie.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
use phpFastCache\CacheManager;
2222

2323
// Include composer autoloader
24-
require '../vendor/autoload.php';
24+
require '../src/autoload.php';
25+
26+
$config = array(
27+
"limited_memory_each_object" => 4000,
28+
);
29+
CacheManager::setup($config);
2530

2631
$InstanceCache = CacheManager::getInstance('cookie');
2732

src/phpFastCache/Core/phpFastCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class phpFastCache
8181

8282
'extensions' => array(),
8383
"cache_method" => 2, // 1 = normal, 2 = phpfastcache, 3 = memory
84-
"limited_memory_each_object" => 128000, // maximum size (bytes) of object store in memory
84+
"limited_memory_each_object" => 4000, // maximum size (bytes) of object store in memory
8585
);
8686

8787
/**

src/phpFastCache/Drivers/cookie.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ public function driver_set($keyword, $value = '', $time = 300, $option = array()
7272
{
7373
$this->connectServer();
7474
$keyword = 'phpFastCache_' . $keyword;
75-
return setcookie($keyword, $this->encode($value), time() + ($time ? (int)$time : 300), '/');
75+
$v = $this->encode($value);
76+
if(isset($this->config['limited_memory_each_object'])
77+
&& strlen($v) > $this->config['limited_memory_each_object']) {
78+
return false;
79+
}
80+
return setcookie($keyword, $v, time() + ($time ? (int)$time : 300), '/');
7681

7782
}
7883

0 commit comments

Comments
 (0)