Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 77b0526

Browse files
Merge branch 'master' of github.com:mikebronner/laravel-model-caching
2 parents 1f3cf3f + 83b2619 commit 77b0526

File tree

6 files changed

+25
-15
lines changed

6 files changed

+25
-15
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ The following are packages we have identified as conflicting:
6767
- [spatie/laravel-query-builder](https://github.com/spatie/laravel-query-builder)
6868
- [dwightwatson/rememberable](https://github.com/dwightwatson/rememberable)
6969
- [kalnoy/nestedset](https://github.com/lazychaser/laravel-nestedset)
70+
- [laravel-adjacency-list](https://github.com/staudenmeir/laravel-adjacency-list)
7071

7172
### Things That Don't Work Currently
7273
The following items currently do no work with this package:

‎composer.json‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@
1717
"require": {
1818
"php": ">=8.1",
1919
"genealabs/laravel-pivot-events": "^10.0|^11.0",
20-
"illuminate/cache": "^10.0|^11.0",
21-
"illuminate/config": "^10.0|^11.0",
22-
"illuminate/console": "^10.0|^11.0",
23-
"illuminate/container": "^10.0|^11.0",
24-
"illuminate/database": "^10.0|^11.0",
25-
"illuminate/http": "^10.0|^11.0",
26-
"illuminate/support": "^10.0|^11.0"
20+
"illuminate/cache": "^10.0|^11.0|^12.0",
21+
"illuminate/config": "^10.0|^11.0|^12.0",
22+
"illuminate/console": "^10.0|^11.0|^12.0",
23+
"illuminate/container": "^10.0|^11.0|^12.0",
24+
"illuminate/database": "^10.0|^11.0|^12.0",
25+
"illuminate/http": "^10.0|^11.0|^12.0",
26+
"illuminate/support": "^10.0|^11.0|^12.0"
2727
},
2828
"require-dev": {
29-
"doctrine/dbal": "^3.3",
29+
"doctrine/dbal": "^3.3|^4.2",
3030
"fakerphp/faker": "^1.11",
3131
"laravel/nova": "^4.0",
32-
"orchestra/testbench-browser-kit": "^9.0",
33-
"orchestra/testbench": "^9.0",
32+
"orchestra/testbench-browser-kit": "^9.0|^10.0",
33+
"orchestra/testbench": "^9.0|^10.0",
3434
"php-coveralls/php-coveralls": "^2.2",
35-
"phpunit/phpunit": "^10.5",
35+
"phpunit/phpunit": "^10.5|^11.5.3",
3636
"slevomat/coding-standard": "^7.0|^8.14",
3737
"squizlabs/php_codesniffer": "^3.6",
3838
"symfony/thanks": "^1.2",

‎src/CacheKey.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ protected function getQueryColumns(array $columns) : string
263263
return "_" . implode("_", $columns);
264264
}
265265

266+
$columns = array_map(function ($column) {
267+
return $this->expressionToString($column);
268+
}, $columns);
269+
266270
return "_" . implode("_", $columns);
267271
}
268272

‎src/Traits/BuilderCaching.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function withoutGlobalScope($scope)
3131
return parent::withoutGlobalScope($scope);
3232
}
3333

34-
public function withoutGlobalScopes(array $scopes = null)
34+
public function withoutGlobalScopes(?array $scopes = null)
3535
{
3636
if ($scopes !== null) {
3737
$this->withoutGlobalScopes = $scopes;

‎src/Traits/Caching.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ protected function checkCooldownAndRemoveIfExpired(Model $instance)
241241

242242
if (
243243
! $cacheCooldown
244-
|| (new Carbon)->now()->diffInSeconds($invalidatedAt) < $cacheCooldown
244+
|| (new Carbon)->now()->diffInSeconds($invalidatedAt, true) < $cacheCooldown
245245
) {
246246
return;
247247
}
@@ -285,7 +285,7 @@ protected function checkCooldownAndFlushAfterPersisting(Model $instance, string
285285

286286
$this->setCacheCooldownSavedAtTimestamp($instance);
287287

288-
if ((new Carbon)->now()->diffInSeconds($invalidatedAt) >= $cacheCooldown) {
288+
if ((new Carbon)->now()->diffInSeconds($invalidatedAt, true) >= $cacheCooldown) {
289289
$instance->flushCache();
290290

291291
if ($relationship) {

‎src/Traits/ModelCaching.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public function __get($key)
2222
?? 0;
2323
}
2424

25+
if ($key === "query") {
26+
return $this->query
27+
?? $this->newModelQuery();
28+
}
29+
2530
return parent::__get($key);
2631
}
2732

@@ -160,7 +165,7 @@ public function scopeDisableCache(EloquentBuilder $query) : EloquentBuilder
160165

161166
public function scopeWithCacheCooldownSeconds(
162167
EloquentBuilder $query,
163-
int $seconds = null
168+
?int $seconds = null
164169
) : EloquentBuilder {
165170
if (! $seconds) {
166171
$seconds = $this->cacheCooldownSeconds;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /