Skip to content

Commit b73f0d1

Browse files
authored
Merge pull request #155 from NotFoundNL/develop
fix: caching error
2 parents 22ed7f0 + 30a0831 commit b73f0d1

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/Models/BaseModel.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace NotFound\Framework\Models;
46

57
use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -33,10 +35,22 @@ class BaseModel extends Model
3335
*/
3436
protected $visible = [''];
3537

36-
public function v()
38+
/**
39+
* Fetch the cached values for this model
40+
* based on the CMS settings.
41+
*
42+
* As this is causes heavy use of resources we'll cache
43+
* the result for a week.
44+
*/
45+
public function v(): AssetValues
3746
{
38-
$cacheKey = 'table_'.$this->table.'_'.$this->id.'_'.Lang::current()->url.($this->updated_at ?? '');
39-
$secondsToRemember = 7 * 24 * 60 * 60;
47+
$updated = '';
48+
$secondsToRemember = 3600;
49+
if (isset($this->updated_at) && $this->updated_at !== null) {
50+
$secondsToRemember = 7 * 24 * 60 * 60;
51+
$updated = (string) $this->updated_at->getTimeStamp();
52+
}
53+
$cacheKey = 'table_'.$this->table.'_'.$this->id.'_'.Lang::current()->url.$updated;
4054

4155
return Cache::remember($cacheKey, $secondsToRemember, function () {
4256
$tableService = new TableService(Table::whereTable($this->table)->first(), Lang::current(), $this->id);

0 commit comments

Comments
 (0)