From 3c79ec5b4c760e736a1120bd7a4ae81f2a74a2de Mon Sep 17 00:00:00 2001 From: Khoa Bui Date: Thu, 24 Mar 2016 13:36:08 -0700 Subject: [PATCH 1/2] Cookie limited --- src/phpFastCache/Core/phpFastCache.php | 2 +- src/phpFastCache/Drivers/cookie.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/phpFastCache/Core/phpFastCache.php b/src/phpFastCache/Core/phpFastCache.php index 1650edf9e..f1ca2b3b5 100644 --- a/src/phpFastCache/Core/phpFastCache.php +++ b/src/phpFastCache/Core/phpFastCache.php @@ -81,7 +81,7 @@ class phpFastCache 'extensions' => array(), "cache_method" => 2, // 1 = normal, 2 = phpfastcache, 3 = memory - "limited_memory_each_object" => 128000, // maximum size (bytes) of object store in memory + "limited_memory_each_object" => 4000, // maximum size (bytes) of object store in memory ); /** diff --git a/src/phpFastCache/Drivers/cookie.php b/src/phpFastCache/Drivers/cookie.php index 82c15cf8c..13262415e 100644 --- a/src/phpFastCache/Drivers/cookie.php +++ b/src/phpFastCache/Drivers/cookie.php @@ -72,7 +72,12 @@ public function driver_set($keyword, $value = '', $time = 300, $option = array() { $this->connectServer(); $keyword = 'phpFastCache_' . $keyword; - return setcookie($keyword, $this->encode($value), time() + ($time ? (int)$time : 300), '/'); + $v = $this->encode($value); + if(isset($this->config['limited_memory_each_object']) + && strlen($v) > $this->config['limited_memory_each_object']) { + return false; + } + return setcookie($keyword, $v, time() + ($time ? (int)$time : 300), '/'); } From 8cb1cf645f8666e0e00f8d0ef55c8fafa8ea967d Mon Sep 17 00:00:00 2001 From: Khoa Bui Date: Thu, 24 Mar 2016 13:37:59 -0700 Subject: [PATCH 2/2] cookie example --- examples/cookie.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/cookie.php b/examples/cookie.php index 2980dea8c..64aad47f4 100644 --- a/examples/cookie.php +++ b/examples/cookie.php @@ -21,7 +21,12 @@ use phpFastCache\CacheManager; // Include composer autoloader -require '../vendor/autoload.php'; +require '../src/autoload.php'; + +$config = array( + "limited_memory_each_object" => 4000, +); +CacheManager::setup($config); $InstanceCache = CacheManager::getInstance('cookie');