Skip to content

Commit 92fc0a3

Browse files
committed
feat: Added global config
1 parent 2b1c28b commit 92fc0a3

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,31 @@ You can install the package via composer:
3535
composer require elipzis/laravel-cacheable-model
3636
```
3737

38+
You can publish the config file with:
39+
40+
```bash
41+
php artisan vendor:publish --tag="cacheable-model-config"
42+
```
43+
44+
This is the contents of the published config file:
45+
46+
```php
47+
//Default values for the Cacheable trait - Can be overridden per model
48+
return [
49+
//How long should cache last in general?
50+
'ttl' => 300,
51+
//By what should cache entries be prefixed?
52+
'prefix' => 'cacheable',
53+
//What is the identifying, unique column name?
54+
'identifier' => 'id',
55+
//Do you need logging?
56+
'logging' => [
57+
'enabled' => false,
58+
'level' => 'debug',
59+
],
60+
];
61+
```
62+
3863
## Usage
3964

4065
Make your model cacheable by adding the trait:

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "elipzis/laravel-cacheable-model",
3-
"description": "Query-based cacheable models on-the-fly for your Laravel app",
3+
"description": "Automatic query-based model cache for your Laravel app",
44
"keywords": [
55
"elipZis",
66
"laravel",
@@ -22,8 +22,8 @@
2222
}
2323
],
2424
"require": {
25-
"php": "^8.0|^8.1",
26-
"spatie/laravel-package-tools": "^1.9.2",
25+
"php": "^8.0",
26+
"spatie/laravel-package-tools": "^1.13",
2727
"illuminate/contracts": "^9.0"
2828
},
2929
"require-dev": {

config/cacheable.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
//Default values for the Cacheable trait - Can be overridden per model
4+
return [
5+
//How long should cache last in general?
6+
'ttl' => 300,
7+
//By what should cache entries be prefixed?
8+
'prefix' => 'cacheable',
9+
//What is the identifying, unique column name?
10+
'identifier' => 'id',
11+
//Do you need logging?
12+
'logging' => [
13+
'enabled' => false,
14+
'level' => 'debug',
15+
],
16+
];

src/CacheableServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ class CacheableServiceProvider extends PackageServiceProvider
1919
*/
2020
public function configurePackage(Package $package): void
2121
{
22-
$package->name('laravel-cacheable-model');
22+
$package->name('laravel-cacheable-model')->hasConfigFile('cacheable');
2323
}
2424
}

src/Models/Traits/Cacheable.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ protected function newBaseQueryBuilder()
3232
public function getCacheableProperties(): array
3333
{
3434
return [
35-
'ttl' => 300,
36-
'prefix' => 'cacheable',
37-
'identifier' => 'id',
35+
'ttl' => config('cacheable.ttl', 300),
36+
'prefix' => config('cacheable.prefix', 'cacheable'),
37+
'identifier' => config('cacheable.identifier', 'id'),
3838
'logging' => [
39-
'enabled' => false,
40-
'level' => 'debug',
39+
'enabled' => config('cacheable.logging.enabled', false),
40+
'level' => config('cacheable.logging.level', 'debug',),
4141
],
4242
];
4343
}

0 commit comments

Comments
 (0)