27 #require_once 'Zend/Cache/Core.php'; 85 'http_conditional' =>
false,
86 'debug_header' =>
false,
87 'content_type_memorization' =>
false,
88 'memorize_headers' => array(),
89 'default_options' => array(
90 'cache_with_get_variables' =>
false,
91 'cache_with_post_variables' =>
false,
92 'cache_with_session_variables' =>
false,
93 'cache_with_files_variables' =>
false,
94 'cache_with_cookie_variables' =>
false,
95 'make_id_with_get_variables' =>
true,
96 'make_id_with_post_variables' =>
true,
97 'make_id_with_session_variables' =>
true,
98 'make_id_with_files_variables' =>
true,
99 'make_id_with_cookie_variables' =>
true,
101 'specific_lifetime' =>
false,
138 case 'default_options':
141 case 'content_type_memorization':
148 if (isset($this->_specificOptions[
'http_conditional'])) {
149 if ($this->_specificOptions[
'http_conditional']) {
153 $this->
setOption(
'automatic_serialization',
true);
169 if (!is_string($key)) {
172 $key = strtolower($key);
173 if (isset($this->_specificOptions[
'default_options'][$key])) {
174 $this->_specificOptions[
'default_options'][$key] =
$value;
189 foreach ($this->_specificOptions[
'memorize_headers'] as $key =>
$value) {
190 if (strtolower(
$value) ==
'content-type') {
196 $this->_specificOptions[
'memorize_headers'][] =
'Content-Type';
200 unset($this->_specificOptions[
'memorize_headers'][$found]);
214 if (!is_array($regexps)) {
217 foreach ($regexps as $regexp=>$conf) {
218 if (!is_array($conf)) {
221 $validKeys = array_keys($this->_specificOptions[
'default_options']);
222 foreach ($conf as $key=>
$value) {
223 if (!is_string($key)) {
226 $key = strtolower($key);
227 if (!in_array($key, $validKeys)) {
228 unset($regexps[$regexp][$key]);
242 public function start(
$id =
false, $doNotDie =
false)
244 $this->_cancel =
false;
245 $lastMatchingRegexp =
null;
246 if (isset($_SERVER[
'REQUEST_URI'])) {
247 foreach ($this->_specificOptions[
'regexps'] as $regexp => $conf) {
248 if (preg_match(
"`$regexp`", $_SERVER[
'REQUEST_URI'])) {
249 $lastMatchingRegexp = $regexp;
253 $this->_activeOptions = $this->_specificOptions[
'default_options'];
254 if ($lastMatchingRegexp !==
null) {
255 $conf = $this->_specificOptions[
'regexps'][$lastMatchingRegexp];
256 foreach ($conf as $key=>
$value) {
257 $this->_activeOptions[$key] =
$value;
260 if (!($this->_activeOptions[
'cache'])) {
270 if ($array !==
false) {
271 $data = $array[
'data'];
272 $headers = $array[
'headers'];
274 foreach ($headers as $key=>$headerCouple) {
275 $name = $headerCouple[0];
276 $value = $headerCouple[1];
277 header(
"$name: $value");
280 if ($this->_specificOptions[
'debug_header']) {
281 echo
'DEBUG HEADER : This is a cached page !';
289 ob_start(array($this,
'_flush'));
290 ob_implicit_flush(
false);
299 $this->_cancel =
true;
311 if ($this->_cancel) {
315 $storedHeaders = array();
316 $headersList = headers_list();
317 foreach($this->_specificOptions[
'memorize_headers'] as $key=>$headerName) {
318 foreach ($headersList as $headerSent) {
319 $tmp = explode(
':', $headerSent);
320 $headerSentName = trim(array_shift($tmp));
321 if (strtolower($headerName) == strtolower($headerSentName)) {
322 $headerSentValue = trim(implode(
':', $tmp));
323 $storedHeaders[] = array($headerSentName, $headerSentValue);
329 'headers' => $storedHeaders
331 $this->
save($array,
null, $this->_activeOptions[
'tags'], $this->_activeOptions[
'specific_lifetime'], $this->_activeOptions[
'priority']);
342 $tmp = $_SERVER[
'REQUEST_URI'];
343 $array = explode(
'?', $tmp, 2);
345 foreach (array(
'Get',
'Post',
'Session',
'Files',
'Cookie') as $arrayName) {
346 $tmp2 = $this->
_makePartialId($arrayName, $this->_activeOptions[
'cache_with_' . strtolower($arrayName) .
'_variables'], $this->_activeOptions[
'make_id_with_' . strtolower($arrayName) .
'_variables']);
365 switch ($arrayName) {
373 if (isset($_SESSION)) {
380 if (isset($_COOKIE)) {
394 return serialize($var);
398 if (is_array($var) && count($var) > 0) {
start($id=false, $doNotDie=false)
save($data, $id=null, $tags=array(), $specificLifetime=false, $priority=8)
_setContentTypeMemorization($value)
__construct(array $options=array())
_makePartialId($arrayName, $bool1, $bool2)
static throwException($msg, Exception $e=null)
load($id, $doNotTestCacheValidity=false, $doNotUnserialize=false)
_setDefaultOptions($options)
if(!isset($_GET['name'])) $name