WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 86cf57d

Browse files
author
Josh Ralph
committed
Merge remote-tracking branch 'upstream/master' into laravel-11-upstream-merge
2 parents 431b4ca + 03ac026 commit 86cf57d

File tree

10 files changed

+45
-29
lines changed

10 files changed

+45
-29
lines changed

.github/workflows/laravel.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: true
1616
matrix:
17-
php: [8.3, 8.2]
17+
php: [8.4, 8.3, 8.2]
1818

1919
name: PHP ${{ matrix.php }}
2020

README.md

Lines changed: 2 additions & 1 deletion
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:
@@ -81,7 +82,7 @@ The following items currently do no work with this package:
8182
## Installation
8283
Be sure to not require a specific version of this package when requiring it:
8384
```
84-
composer require genealabs/laravel-model-caching
85+
composer require mikebronner/laravel-model-caching
8586
```
8687

8788
### Gotchas If Using With Lumen

composer.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "genealabs/laravel-model-caching",
2+
"name": "mikebronner/laravel-model-caching",
33
"description": "Automatic caching for Eloquent models.",
44
"license": "MIT",
55
"authors": [
@@ -16,23 +16,23 @@
1616
],
1717
"require": {
1818
"php": ">=8.1",
19-
"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"
19+
"mikebronner/laravel-pivot-events": "^10.0|^11.0|^12.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",
31-
"laravel/nova": "^4.0",
32-
"orchestra/testbench-browser-kit": "^9.0",
33-
"orchestra/testbench": "^9.0",
31+
"laravel/nova": "^5.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",

phpunit.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
<env name="QUEUE_DRIVER" value="sync"/>
3232
<env name="DB_CONNECTION" value="sqlite"/>
3333
<env name="DB_DATABASE" value=":memory:"/>
34-
<env name="REDIS_HOST" value="redis"/>
35-
<env name="PGSQL_HOST" value="pgsql"/>
36-
<env name="PGSQL_USERNAME" value="forge"/>
37-
<env name="PGSQL_PASSWORD" value="secret"/>
34+
<env name="REDIS_HOST" value="127.0.0.1"/>
35+
<env name="PGSQL_HOST" value="127.0.0.1"/>
36+
<env name="PGSQL_USERNAME" value="root"/>
37+
<env name="PGSQL_PASSWORD" value=""/>
3838
<env name="PGSQL_DATABASE" value="testing"/>
3939
</php>
4040
<source>

src/CacheKey.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,11 @@ protected function getQueryColumns(array $columns) : string
276276
return "_" . implode("_", $columns);
277277
}
278278

279-
return "_" . implode("_", array_map(function ($column) {
279+
$columns = array_map(function ($column) {
280280
return $this->expressionToString($column);
281-
}, $columns));
281+
}, $columns);
282+
283+
return "_" . implode("_", $columns);
282284
}
283285

284286
protected function getRawClauses(array $where) : string

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;

tests/Integration/CachedModelTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Integration;
22

33
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author;
4+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\AuthorWithCooldown;
45
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book;
56
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\PrefixedAuthor;
67
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor;
78
use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase;
8-
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\AuthorWithCooldown;
99
use ReflectionClass;
1010

1111
class CachedModelTest extends IntegrationTestCase
@@ -169,7 +169,7 @@ public function testCooldownIsQueriedForCooldownModels()
169169
$author = (new AuthorWithCooldown)
170170
->withCacheCooldownSeconds(1)
171171
->first();
172-
172+
173173
[$usesCacheCooldown, $expiresAt, $savedAt] = $method->invokeArgs($author, [$author]);
174174

175175
$this->assertEquals($usesCacheCooldown, 1);
@@ -188,7 +188,7 @@ public function testModelCacheDoesntInvalidateDuringCooldownPeriod()
188188
->get();
189189
$uncachedAuthors = (new UncachedAuthor)
190190
->get();
191-
sleep(2);
191+
sleep(3);
192192
$authorsAfterCooldown = (new AuthorWithCooldown)
193193
->get();
194194

tests/NovaTestCase.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace GeneaLabs\LaravelModelCaching\Tests;
46

57
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Nova\AuthorResource;
68
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Nova\BookResource;
79
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Nova\StoreResource;
810
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Providers\NovaServiceProvider;
911
use Illuminate\Contracts\Auth\Authenticatable;
12+
use Illuminate\Support\Facades\Artisan;
13+
use Inertia\ServiceProvider;
1014
use Laravel\Nova\Nova;
1115
use Laravel\Nova\NovaCoreServiceProvider;
1216

@@ -34,6 +38,9 @@ public function setUp(): void
3438
});
3539

3640
$this->authenticate();
41+
$this->withoutMiddleware();
42+
43+
Artisan::call("nova:publish");
3744
}
3845

3946
protected function authenticate()
@@ -54,6 +61,7 @@ protected function getPackageProviders($app)
5461
NovaCoreServiceProvider::class,
5562
\Laravel\Nova\NovaServiceProvider::class,
5663
NovaServiceProvider::class,
64+
ServiceProvider::class,
5765
]
5866
);
5967
}

0 commit comments

Comments
 (0)