Skip to content

Commit

Permalink
feat: if Laravel detected, then use Laravel cache
Browse files Browse the repository at this point in the history
  • Loading branch information
fredbradley committed Nov 3, 2023
1 parent 698a285 commit 9ea0b37
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use League\Flysystem\Local\LocalFilesystemAdapter;
use Saloon\CachePlugin\Data\CachedResponse;
use Saloon\CachePlugin\Drivers\FlysystemDriver;
use Saloon\CachePlugin\Drivers\LaravelCacheDriver;

class Cache
{
Expand All @@ -20,10 +21,14 @@ public static function fileSystem(): Filesystem

public static function driver(): FlysystemDriver
{
self::purgeExpired();
return new FlysystemDriver(
self::fileSystem()
);
if (class_exists('\Illuminate\Support\Facades\Cache')) {
return new LaravelCacheDriver(\Illuminate\Support\Facades\Cache::getDefaultDriver());
} else {
self::purgeExpired();
return new FlysystemDriver(
self::fileSystem()
);
}
}

public static function purgeExpired(): void
Expand Down

0 comments on commit 9ea0b37

Please sign in to comment.