Skip to content

Commit 1d8dbc1

Browse files
committed
ability to customise the cache key prefix
1 parent 4f60ca0 commit 1d8dbc1

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

config/log-viewer.php

+13
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,19 @@
204204

205205
'cache_driver' => env('LOG_VIEWER_CACHE_DRIVER', null),
206206

207+
/*
208+
|--------------------------------------------------------------------------
209+
| Cache key prefix
210+
|--------------------------------------------------------------------------
211+
| Log Viewer prefixes all the cache keys created with this value. If for
212+
| some reason you would like to change this prefix, you can do so here.
213+
| The format of Log Viewer cache keys is:
214+
| {prefix}:{version}:{rest-of-the-key}
215+
|
216+
*/
217+
218+
'cache_key_prefix' => 'lv',
219+
207220
/*
208221
|--------------------------------------------------------------------------
209222
| Chunk size when scanning log files lazily

src/Utils/GenerateCacheKey.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ public static function for(mixed $object, ?string $namespace = null): string
3333

3434
protected static function baseKey(): string
3535
{
36-
return 'lv:'.LogViewer::version();
36+
return config('log-viewer.cache_key_prefix', 'lv').':'.LogViewer::version();
3737
}
3838
}

tests/Unit/GenerateCacheKeyTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
);
1515
});
1616

17+
it('can configure the cache key prefix', function () {
18+
config(['log-viewer.cache_key_prefix' => $customPrefix = 'lvCustom']);
19+
20+
$file = new LogFile('test.log');
21+
22+
$result = GenerateCacheKey::for($file);
23+
24+
expect($result)->toBe(
25+
$customPrefix.':'.LogViewer::version().':file:'.$file->identifier
26+
);
27+
});
28+
1729
it('can pass a namespace for a more specific cache key', function () {
1830
$file = new LogFile('test.log');
1931

0 commit comments

Comments
 (0)