Skip to content

Commit

Permalink
Merge pull request #260 from khoaofgod/final
Browse files Browse the repository at this point in the history
Cookie limited
  • Loading branch information
khoaofgod committed Mar 24, 2016
2 parents 68f0d46 + 8cb1cf6 commit 8ccdb78
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion examples/cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion src/phpFastCache/Core/phpFastCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

/**
Expand Down
7 changes: 6 additions & 1 deletion src/phpFastCache/Drivers/cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -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), '/');

}

Expand Down

0 comments on commit 8ccdb78

Please sign in to comment.