Skip to content

Commit

Permalink
ability to customise the cache key prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
arukompas committed May 17, 2024
1 parent 4f60ca0 commit 1d8dbc1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
13 changes: 13 additions & 0 deletions config/log-viewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,19 @@

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

/*
|--------------------------------------------------------------------------
| Cache key prefix
|--------------------------------------------------------------------------
| Log Viewer prefixes all the cache keys created with this value. If for
| some reason you would like to change this prefix, you can do so here.
| The format of Log Viewer cache keys is:
| {prefix}:{version}:{rest-of-the-key}
|
*/

'cache_key_prefix' => 'lv',

/*
|--------------------------------------------------------------------------
| Chunk size when scanning log files lazily
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/GenerateCacheKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public static function for(mixed $object, ?string $namespace = null): string

protected static function baseKey(): string
{
return 'lv:'.LogViewer::version();
return config('log-viewer.cache_key_prefix', 'lv').':'.LogViewer::version();
}
}
12 changes: 12 additions & 0 deletions tests/Unit/GenerateCacheKeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
);
});

it('can configure the cache key prefix', function () {
config(['log-viewer.cache_key_prefix' => $customPrefix = 'lvCustom']);

$file = new LogFile('test.log');

$result = GenerateCacheKey::for($file);

expect($result)->toBe(
$customPrefix.':'.LogViewer::version().':file:'.$file->identifier
);
});

it('can pass a namespace for a more specific cache key', function () {
$file = new LogFile('test.log');

Expand Down

0 comments on commit 1d8dbc1

Please sign in to comment.