Skip to content

Commit 95af8ec

Browse files
feat: setup project
1 parent 55ec689 commit 95af8ec

File tree

8 files changed

+27
-86
lines changed

8 files changed

+27
-86
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/giacomomasseron/laravel-cache-when-db/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/giacomomasseron/laravel-cache-when-db/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
66
[![Total Downloads](https://img.shields.io/packagist/dt/giacomomasseron/laravel-cache-when-db.svg?style=flat-square)](https://packagist.org/packages/giacomomasseron/laravel-cache-when-db)
77

8+
Clean cache keys when you insert, update or delete some records of your database.
9+
810
## Installation
911

1012
You can install the package via composer:
@@ -16,15 +18,15 @@ composer require giacomomasseron/laravel-cache-when-db
1618
You can publish the config file with:
1719

1820
```bash
19-
php artisan vendor:publish --tag="laravel-cache-when-db-config"
21+
php artisan vendor:publish --tag="laravel-cache-when-db"
2022
```
2123

2224
This is the contents of the published config file:
2325

2426
```php
2527
return [
2628
/**
27-
* Define Cache keys to clean when something happens in the database
29+
* Define Cache keys to clean when one the tables of the array is updated
2830
*
2931
* [
3032
* 'cache_key' => [

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"laravel-cache-when-db",
88
"eloquent"
99
],
10-
"homepage": "https://github.com/giacomomasseron/laravel-models-generator",
10+
"homepage": "https://github.com/giacomomasseron/laravel-cache-when-db",
1111
"license": "MIT",
1212
"authors": [
1313
{
@@ -34,7 +34,7 @@
3434
"extra": {
3535
"laravel": {
3636
"providers": [
37-
"LaravelCacheWhenDbServiceProvider"
37+
"GiacomoMasseroni\\LaravelCacheWhenDb\\LaravelCacheWhenDbServiceProvider"
3838
]
3939
}
4040
},
File renamed without changes.

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ parameters:
77
- src/
88

99
# Level 9 is the highest level
10-
level: 5
10+
level: 8
1111

1212
# ignoreErrors:
1313
# - '#PHPDoc tag @var#'

src/LaravelCacheWhenDb.php

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

3+
declare(strict_types=1);
4+
35
namespace GiacomoMasseroni\LaravelCacheWhenDb;
46

57
use Illuminate\Support\Facades\Cache;
@@ -13,8 +15,12 @@ public static function queryChangedDatabase(string $sql): bool
1315
return str_starts_with($sql, 'INSERT') || str_starts_with($sql, 'UPDATE') || str_starts_with($sql, 'DELETE');
1416
}
1517

16-
public static function clearCache(string $sql): void
18+
public static function cleanCache(string $sql): void
1719
{
20+
/**
21+
* @var string $key
22+
* @var array<string> $dbTables
23+
*/
1824
foreach (config('laravel-cache-when-db', []) as $key => $dbTables) {
1925
$clean = false;
2026

src/LaravelCacheWhenDbServiceProvider.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,29 @@
22

33
declare(strict_types=1);
44

5-
namespace Crurated\ApiUseCaseManagement;
5+
namespace GiacomoMasseroni\LaravelCacheWhenDb;
66

7-
use GiacomoMasseroni\LaravelCacheWhenDb\LaravelCacheWhenDb;
7+
use Illuminate\Database\Events\QueryExecuted;
88
use Illuminate\Support\Facades\DB;
99
use Illuminate\Support\ServiceProvider;
1010

1111
class LaravelCacheWhenDbServiceProvider extends ServiceProvider
1212
{
13-
public function register()
13+
public function register(): void
1414
{
15-
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'laravel-cache-when-db');
15+
$this->mergeConfigFrom(__DIR__.'/../config/laravel-cache-when-db.php', 'laravel-cache-when-db');
1616
}
1717

18-
public function boot()
18+
public function boot(): void
1919
{
20-
if ($this->app->runningInConsole()) {
21-
$this->publishes([
22-
__DIR__.'/../config/config.php' => config_path('laravel-cache-when-db'),
23-
]);
20+
$this->publishes([
21+
__DIR__.'/../config/laravel-cache-when-db.php' => config_path('laravel-cache-when-db.php'),
22+
]);
2423

25-
DB::listen(function ($query): void {
26-
if (LaravelCacheWhenDb::queryChangedDatabase($query->sql)) {
27-
LaravelCacheWhenDb::clearCache($query->sql);
28-
}
29-
});
30-
}
24+
DB::listen(function (QueryExecuted $query): void {
25+
if (LaravelCacheWhenDb::queryChangedDatabase($query->sql)) {
26+
LaravelCacheWhenDb::cleanCache($query->sql);
27+
}
28+
});
3129
}
3230
}

tests/Unit/CacheTest.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

tests/Unit/EventsQueueTest.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)