Skip to content

Commit ab3b32d

Browse files
author
Jan Jurgens
committed
Added compression support for Memcache driver
- Added config field: compress_data - If compress_data is set, enabled compression in Memcache driver
1 parent 2a6b72b commit ab3b32d

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/phpFastCache/Core/phpFastCache.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class phpFastCache
8282
'extensions' => array(),
8383
"cache_method" => 1, // 1 = normal, 2 = phpfastcache, 3 = memory
8484
"limited_memory_each_object" => 4000, // maximum size (bytes) of object store in memory
85+
"compress_data" => false // compress stored data, if the backend supports it
8586
);
8687

8788
/**

src/phpFastCache/Drivers/memcache.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class memcache extends DriverAbstract
2929
*/
3030
public $instant;
3131

32+
/**
33+
* @var int
34+
*/
35+
private $flags = 0;
36+
3237
/**
3338
* phpFastCache_memcache constructor.
3439
* @param array $config
@@ -41,10 +46,13 @@ public function __construct($config = array())
4146
}
4247
if (class_exists('Memcache')) {
4348
$this->instant = new MemcacheSoftware();
49+
50+
if (isset($config[ 'compress_data' ]) && $config[ 'compress_data' ] === true) {
51+
$this->flags = MEMCACHE_COMPRESSED;
52+
}
4453
} else {
4554
$this->fallback = true;
4655
}
47-
4856
}
4957

5058
/**
@@ -113,10 +121,10 @@ public function driver_set(
113121
}
114122

115123
if (isset($option[ 'skipExisting' ]) && $option[ 'skipExisting' ] == true) {
116-
return $this->instant->add($keyword, $value, false, $time);
124+
return $this->instant->add($keyword, $value, $this->flags, $time);
117125

118126
} else {
119-
return $this->instant->set($keyword, $value, false, $time);
127+
return $this->instant->set($keyword, $value, $this->flags, $time);
120128
}
121129
}
122130

@@ -127,7 +135,6 @@ public function driver_set(
127135
*/
128136
public function driver_get($keyword, $option = array())
129137
{
130-
131138
$this->connectServer();
132139

133140
// return null if no caching

0 commit comments

Comments
 (0)