-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
262 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,48 @@ | ||
<?php | ||
<?php /** @noinspection AutoloadingIssuesInspection */ | ||
/** | ||
* Copyright (c) 2016 Jorge Patricio Castro Castillo MIT License. | ||
*/ | ||
include "../lib/BladeOne.php"; | ||
include '../lib/BladeOne.php'; | ||
|
||
include "../lib/BladeOneCache.php"; | ||
include '../lib/BladeOneCache.php'; | ||
|
||
use eftec\bladeone\BladeOne; | ||
use eftec\bladeone\BladeOneCache; | ||
|
||
$views = __DIR__ . '/views'; | ||
$compiledFolder = __DIR__ . '/compiled'; | ||
|
||
class myBlade extends BladeOne { | ||
class myBladeCache extends BladeOne | ||
{ | ||
use BladeOneCache; | ||
} | ||
|
||
$blade=new myBlade($views,$compiledFolder); | ||
define("BLADEONE_MODE",0); // (optional) 1=forced (test),2=run fast (production), 0=automatic, default value. | ||
$blade=new myBladeCache($views, $compiledFolder); | ||
define('BLADEONE_MODE', 0); // (optional) 1=forced (test),2=run fast (production), 0=automatic, default value. | ||
|
||
//<editor-fold desc="Example data"> | ||
if ($blade->cacheExpired('TestCache.hellocache',1,5)) { | ||
echo "<b>Logic layer</b>: cache expired, re-reading the list<br>"; | ||
$idGet=md5(serialize($_GET)).md5(serialize($_POST)); | ||
|
||
if ($blade->cacheExpired('TestCache.hellocache', $idGet, 50)) { | ||
echo '<b>Logic layer</b>: cache expired, re-reading the list<br>'; | ||
$list = [1, 2, 3, 4, 5]; | ||
} else { | ||
echo "<b>Logic layer</b>: cache active, i don't read the list<br>"; | ||
$list=[]; | ||
} | ||
|
||
$random=rand(0,9999); | ||
$time=date('h:i:s A',time()); | ||
$timeUpTo=date('h:i:s A',time()+5); // plus 5 seconds | ||
$random=mt_rand(0, 9999); | ||
$time=date('h:i:s A', time()); | ||
$timeUpTo=date('h:i:s A', time()+5); // plus 5 seconds | ||
//</editor-fold> | ||
|
||
|
||
try { | ||
echo $blade->run("TestCache.hellocache" | ||
, ["random" => $random | ||
echo $blade->run('TestCache.hellocache', ['random' => $random | ||
, 'time' => $time | ||
, 'list' => $list | ||
, 'timeUpTo' => $timeUpTo]); | ||
, 'timeUpTo' => $timeUpTo | ||
,'idGet'=>$idGet]); | ||
} catch (Exception $e) { | ||
echo "error found ".$e->getMessage()."<br>".$e->getTraceAsString(); | ||
echo 'error found ' .$e->getMessage(). '<br>' .$e->getTraceAsString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php /** @noinspection AutoloadingIssuesInspection */ | ||
/** | ||
* Copyright (c) 2016 Jorge Patricio Castro Castillo MIT License. | ||
*/ | ||
include '../lib/BladeOne.php'; | ||
|
||
include '../lib/BladeOneCache.php'; | ||
|
||
use eftec\bladeone\BladeOne; | ||
use eftec\bladeone\BladeOneCache; | ||
|
||
|
||
class myBladeCache extends BladeOne | ||
{ | ||
use BladeOneCache; | ||
} | ||
|
||
$blade=new myBladeCache(); | ||
$blade->setCacheStrategy('getpost'); | ||
|
||
define('BLADEONE_MODE', 0); // (optional) 1=forced (test),2=run fast (production), 0=automatic, default value. | ||
|
||
if ($blade->cachePageExpired('TestCache.hellocache2', 5)) { | ||
echo '<b>Logic layer</b>: cache expired, re-reading the list<br>'; | ||
$list = [1, 2, 3, 4, 5]; | ||
} else { | ||
echo "<b>Logic layer</b>: cache active, i don't read the list<br>"; | ||
$list=[]; | ||
} | ||
|
||
|
||
$random=mt_rand(0, 9999); | ||
$time=date('h:i:s A', time()); | ||
$timeUpTo=date('h:i:s A', time()+5); // plus 5 seconds | ||
//</editor-fold> | ||
|
||
|
||
try { | ||
echo $blade->runCache('TestCache.hellocache2', ['random' => $random | ||
, 'time' => $time | ||
, 'list' => $list | ||
, 'timeUpTo' => $timeUpTo | ||
], 5); | ||
} catch (Exception $e) { | ||
echo 'error found ' .$e->getMessage(). '<br>' .$e->getTraceAsString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<body> | ||
<h1>Cache test</h1> | ||
<h2>Test the cache system. Two part of the code is cached for 5 seconds</h2> | ||
<h2>Additionally, in testcache.php, the code avoids to re-read a variable if the cache is still active</h2> | ||
<hr> | ||
start of the cache n1:<br> | ||
this information should be cached {{$random}} {{$time}} unless we are past {{$timeUpTo}}<br> | ||
@foreach($list as $item) | ||
{{$item}}<br> | ||
@endforeach | ||
<hr>$_GET:<br> | ||
@dump($_GET) | ||
<hr> | ||
<a href="?id=2">go to ?id=2</a><br> | ||
<a href="?id=3">go to ?id=3</a><br> | ||
|
||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.