Skip to content

Commit ce099d2

Browse files
author
Kirk Fletcher
committed
added ability to have dynamic content variations
1 parent f0e7406 commit ce099d2

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

readme.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,15 @@ The main ->view function accepts 3 arguments:
8282
The above command is quite obvious and will clear the cache for the selected processed view.
8383

8484

85-
$this->pagespeed->plugin('removeComments', true);
85+
$this->pagespeed->plugin('removeComments', BOOL);
8686

8787
The above command can be called at any time (is usually best to call just after instantiating). This will apply the selected filters whilst building the cached rendered view.
8888

89+
90+
$this->pagespeed->allowDynamic(BOOL);
91+
92+
The above command will allow for dynamic page content but will create more caches. New caches will be generated if the data being passed to the view differs in anyway. All variations will be kept in cache and will be sent when the data, view, and slug match.
93+
8994
#### Available plugins
9095

9196

src/Pagespeed.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Pagespeed
1212
{
1313
protected $trimWhiteSpace = false;
1414
protected $removeComments = false;
15+
protected $allowDynamic = false;
1516

1617
/**
1718
* Render view, apply enabled filters, and cache output for lightning fast performance
@@ -25,7 +26,12 @@ public function view($view, $data = [], $slug = '')
2526
{
2627
try {
2728
if (!Auth::check()) {
28-
$cacheRef = ($slug == '') ? md5(strtolower($view)) : md5(strtolower($slug));
29+
30+
if($this->allowDynamic) {
31+
$cacheRef = md5(strtolower($view.$slug) . serialize($data));
32+
}else{
33+
$cacheRef = ($slug == '') ? md5(strtolower($view)) : md5(strtolower($slug));
34+
}
2935

3036
$view = Cache::rememberForever($cacheRef, function () use ($view, $data) {
3137
return $this->renderView($view, $data);
@@ -70,6 +76,17 @@ public function plugin($plugin, $enable = true)
7076
}
7177
}
7278

79+
/**
80+
* Allow cache ref to be based on md5 of the page data + view + slug
81+
* creates more cache files but allows dynamic content
82+
*
83+
* @param bool $state
84+
*/
85+
public function allowDynamicContent($state = true)
86+
{
87+
$this->allowDynamic = $state;
88+
}
89+
7390

7491
/**
7592
* @param $view

0 commit comments

Comments
 (0)