Skip to content

Commit 414c739

Browse files
committed
make cache store configurable
1 parent 091dec8 commit 414c739

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

config/tailwind-merge.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
declare(strict_types=1);
44

55
return [
6+
/*
7+
|--------------------------------------------------------------------------
8+
| Cache Store
9+
|--------------------------------------------------------------------------
10+
|
11+
| Tailwind Merge uses Laravel's cache system to store the merged classes.
12+
| Here you can customize the cache store that Tailwind Merge uses.
13+
*/
14+
15+
'cache_store' => env('TAILWIND_MERGE_CACHE_STORE'),
16+
617
/*
718
|--------------------------------------------------------------------------
819
| Prefix

src/TailwindMergeServiceProvider.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44

55
namespace TailwindMerge\Laravel;
66

7+
use Illuminate\Support\Facades\Cache;
78
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
89
use Illuminate\View\Compilers\BladeCompiler;
910
use Illuminate\View\ComponentAttributeBag;
11+
use Psr\SimpleCache\CacheInterface;
1012
use TailwindMerge\Contracts\TailwindMergeContract;
1113
use TailwindMerge\TailwindMerge;
1214

1315
class TailwindMergeServiceProvider extends BaseServiceProvider
1416
{
1517
public function register(): void
1618
{
17-
$this->app->singleton(TailwindMergeContract::class, static fn (): TailwindMerge => TailwindMerge::factory()
19+
$this->app->singleton(TailwindMergeContract::class, fn (): TailwindMerge => TailwindMerge::factory()
1820
->withConfiguration(config('tailwind-merge', []))
19-
->withCache(app('cache')->store()) // @phpstan-ignore-line
21+
->withCache($this->getCacheStore())
2022
->make());
2123

2224
$this->app->alias(TailwindMergeContract::class, 'tailwind-merge');
@@ -90,4 +92,12 @@ public function provides(): array
9092
'tailwind-merge',
9193
];
9294
}
95+
96+
protected function getCacheStore(): CacheInterface
97+
{
98+
/** @var string|null $storage */
99+
$storage = config('tailwind-merge.cache.store');
100+
101+
return Cache::store($storage);
102+
}
93103
}

tests/Arch.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
->expect('TailwindMerge\Laravel\TailwindMergeServiceProvider')
1313
->toOnlyUse([
1414
'Illuminate\Contracts\Support\DeferrableProvider',
15+
'Illuminate\Support\Facades\Cache',
1516
'Illuminate\Support\ServiceProvider',
1617
'Illuminate\View\Compilers\BladeCompiler',
1718
'Illuminate\View\ComponentAttributeBag',
19+
'Psr\SimpleCache\CacheInterface',
1820
'TailwindMerge',
1921

2022
// helpers...

0 commit comments

Comments
 (0)