Skip to content

Commit 9355de9

Browse files
committed
increase hash_directory_level and add gzcompress before save
1 parent 420df10 commit 9355de9

File tree

4 files changed

+79
-3
lines changed

4 files changed

+79
-3
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Lesti_Fpc (http:gordonlesti.com/lestifpc)
4+
*
5+
* PHP version 5
6+
*
7+
* @link https://github.com/GordonLesti/Lesti_Fpc
8+
* @package Lesti_Fpc
9+
* @author Gordon Lesti <info@gordonlesti.com>
10+
* @copyright Copyright (c) 2013-2014 Gordon Lesti (http://gordonlesti.com)
11+
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
12+
*/
13+
14+
/**
15+
* Class Lesti_Fpc_Model_Adminhtml_System_Config_Source_Gzcompress
16+
*/
17+
class Lesti_Fpc_Model_Adminhtml_System_Config_Source_Gzcompress
18+
{
19+
/**
20+
* @return array
21+
*/
22+
public function toOptionArray()
23+
{
24+
$options = array();
25+
foreach ($this->toArray() as $key => $value) {
26+
$options[] = array('value' => $key, 'label' => $value);
27+
}
28+
29+
return $options;
30+
}
31+
32+
/**
33+
* @return array
34+
*/
35+
public function toArray()
36+
{
37+
$options = array(-2 => Mage::helper('fpc')->__('No'));
38+
for ($i=0; $i <10; $i++) {
39+
$options[$i] = $i;
40+
}
41+
42+
return $options;
43+
}
44+
}

app/code/community/Lesti/Fpc/Model/Fpc.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
class Lesti_Fpc_Model_Fpc extends Mage_Core_Model_Cache
1818
{
19+
const GZCOMPRESS_LEVEL_XML_PATH = 'system/fpc/gzcompress_level';
1920
const CACHE_TAG = 'FPC';
2021

2122
/**
@@ -24,7 +25,7 @@ class Lesti_Fpc_Model_Fpc extends Mage_Core_Model_Cache
2425
* @var array
2526
*/
2627
protected $_defaultBackendOptions = array(
27-
'hashed_directory_level' => 3,
28+
'hashed_directory_level' => 6,
2829
'hashed_directory_perm' => 0777,
2930
'file_name_prefix' => 'fpc',
3031
);
@@ -36,7 +37,7 @@ class Lesti_Fpc_Model_Fpc extends Mage_Core_Model_Cache
3637
* @var array
3738
*/
3839
protected $_legacyDefaultBackendOptions = array(
39-
'hashed_directory_level' => 3,
40+
'hashed_directory_level' => 6,
4041
'hashed_directory_umask' => 0777,
4142
'file_name_prefix' => 'fpc',
4243
);
@@ -90,15 +91,35 @@ public function save($data, $id, $tags=array(), $lifeTime=null)
9091
$id = $cacheData->getCacheId();
9192
$tags = $cacheData->getTags();
9293
$lifeTime = $cacheData->getLifeTime();
94+
95+
$compressLevel = Mage::getStoreConfig(self::GZCOMPRESS_LEVEL_XML_PATH);
96+
if ($compressLevel != -2) {
97+
$data = gzcompress($data, $compressLevel);
98+
}
9399

94100
return $this->_frontend->save(
95-
(string)$data,
101+
$data,
96102
$this->_id($id),
97103
$this->_tags($tags),
98104
$lifeTime
99105
);
100106
}
101107

108+
/**
109+
* @param string $id
110+
* @return string
111+
*/
112+
public function load($id)
113+
{
114+
$data = parent::load($id);
115+
$compressLevel = Mage::getStoreConfig(self::GZCOMPRESS_LEVEL_XML_PATH);
116+
if ($compressLevel != -2) {
117+
$data = gzuncompress($data);
118+
}
119+
120+
return $data;
121+
}
122+
102123
/**
103124
* Clean cached data by specific tag
104125
*

app/code/community/Lesti/Fpc/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ display_mode]]></session_params>
253253
<customer_groups>0</customer_groups>
254254
<use_recently_viewed_products>0</use_recently_viewed_products>
255255
<show_age>1</show_age>
256+
<gzcompress_level>-2</gzcompress_level>
256257
</fpc>
257258
</system>
258259
</default>

app/code/community/Lesti/Fpc/etc/system.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@
125125
<show_in_website>1</show_in_website>
126126
<show_in_store>1</show_in_store>
127127
</show_age>
128+
<gzcompress_level>
129+
<label>gzcompress Level</label>
130+
<frontend_type>select</frontend_type>
131+
<comment>Compress the cache (only for filecache, flush Lesti_Fpc after changing value)</comment>
132+
<source_model>fpc/adminhtml_system_config_source_gzcompress</source_model>
133+
<sort_order>100</sort_order>
134+
<show_in_default>1</show_in_default>
135+
<show_in_website>1</show_in_website>
136+
<show_in_store>1</show_in_store>
137+
</gzcompress_level>
128138
</fields>
129139
</fpc>
130140
</groups>

0 commit comments

Comments
 (0)