diff --git a/app/application/app/Enums/CacheTag.php b/app/application/app/Enums/CacheTag.php deleted file mode 100644 index a9e7b6f..0000000 --- a/app/application/app/Enums/CacheTag.php +++ /dev/null @@ -1,18 +0,0 @@ -value); - } -} diff --git a/app/application/app/Http/Middleware/DocumentationVersion.php b/app/application/app/Http/Middleware/DocumentationVersion.php index e71fb39..8f951dc 100644 --- a/app/application/app/Http/Middleware/DocumentationVersion.php +++ b/app/application/app/Http/Middleware/DocumentationVersion.php @@ -2,8 +2,8 @@ namespace App\Http\Middleware; -use App\Enums\CacheTag; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Cache; use Symfony\Component\HttpFoundation\Response; final readonly class DocumentationVersion @@ -17,7 +17,7 @@ final readonly class DocumentationVersion } $seconds = 3600; - $version = CacheTag::DocumantationVersion->getCache()->remember(self::class . $project->id . '-' . $versionSlug, $seconds, function () use ($project, $versionSlug) { + $version = Cache::remember(self::class . $project->id . '-' . $versionSlug, $seconds, function () use ($project, $versionSlug) { return $project->documentationVersions()->where('slug', $versionSlug)->first() ?? false; }); if ($version === false) { diff --git a/app/application/app/Http/Middleware/ProjectAndLanguage.php b/app/application/app/Http/Middleware/ProjectAndLanguage.php index 36a7a63..a2dc478 100644 --- a/app/application/app/Http/Middleware/ProjectAndLanguage.php +++ b/app/application/app/Http/Middleware/ProjectAndLanguage.php @@ -2,8 +2,8 @@ namespace App\Http\Middleware; -use App\Enums\CacheTag; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Cache; use Symfony\Component\HttpFoundation\Response; use Closure; @@ -17,7 +17,7 @@ final class ProjectAndLanguage extends ProjectLanguage } $seconds = 3600; - $project = CacheTag::Project->getCache()->remember(self::class . $projectCode, $seconds, function () use ($projectCode) { + $project = Cache::remember(self::class . $projectCode, $seconds, function () use ($projectCode) { return $this->projectRepository->getProjectByCode($projectCode) ?? false; }); if ($project === false) { diff --git a/app/application/app/Http/Middleware/ProjectDomainAndLanguage.php b/app/application/app/Http/Middleware/ProjectDomainAndLanguage.php index 99d6236..2a7da34 100644 --- a/app/application/app/Http/Middleware/ProjectDomainAndLanguage.php +++ b/app/application/app/Http/Middleware/ProjectDomainAndLanguage.php @@ -2,9 +2,9 @@ namespace App\Http\Middleware; -use App\Enums\CacheTag; use Closure; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Str; use Symfony\Component\HttpFoundation\Response; @@ -21,7 +21,7 @@ final class ProjectDomainAndLanguage extends ProjectLanguage } $seconds = 3600; - $project = CacheTag::Project->getCache()->remember(self::class . $httpHost, $seconds, function () use ($httpHost) { + $project = Cache::remember(self::class . $httpHost, $seconds, function () use ($httpHost) { return $this->projectRepository->getProjectByHttpHost($httpHost) ?? false; }); if ($project === false) { diff --git a/app/application/app/Http/Middleware/ProjectLanguage.php b/app/application/app/Http/Middleware/ProjectLanguage.php index efaea63..f622fd9 100644 --- a/app/application/app/Http/Middleware/ProjectLanguage.php +++ b/app/application/app/Http/Middleware/ProjectLanguage.php @@ -2,13 +2,13 @@ namespace App\Http\Middleware; -use App\Enums\CacheTag; use App\Models\Project; use App\Repositories\ProjectLanguageRepository; use App\Repositories\ProjectRepository; use App\Repositories\ProjectTranslationRepository; use App\Services\WebsiteTranslations; use Illuminate\Support\Facades\App; +use Illuminate\Support\Facades\Cache; abstract class ProjectLanguage { @@ -21,7 +21,7 @@ abstract class ProjectLanguage protected function getWebsiteTranslations(Project $project, ?string $languageCode): ?WebsiteTranslations { $seconds = 3600 * 3; - $language = CacheTag::Project->getCache()->remember(self::class . $project->id . '-' . $languageCode, $seconds, function () use ($project, $languageCode) { + $language = Cache::remember(self::class . $project->id . '-' . $languageCode, $seconds, function () use ($project, $languageCode) { return $this->projectLanguageRepository->getProjectLanguageByCodeOrDefault($project, $languageCode) ?? false; }); if ($language === false) { @@ -34,7 +34,7 @@ abstract class ProjectLanguage } $seconds = 3600 * 24; - $translations = CacheTag::ProjectTranslation->getCache()->remember(self::class . '-translations-' . $project->id . '-' . $language->id, $seconds, function () use ($project, $language) { + $translations = Cache::remember(self::class . '-translations-' . $project->id . '-' . $language->id, $seconds, function () use ($project, $language) { return $this->projectTranslationRepository->getProjectTranslations($project->id, $language->id)->all()->pluck('text', 'code')->toArray(); }); diff --git a/app/application/app/Services/Admin/Project/DocumentationVersionService.php b/app/application/app/Services/Admin/Project/DocumentationVersionService.php index 22ef657..768bbc8 100644 --- a/app/application/app/Services/Admin/Project/DocumentationVersionService.php +++ b/app/application/app/Services/Admin/Project/DocumentationVersionService.php @@ -5,7 +5,6 @@ namespace App\Services\Admin\Project; use App\Dto\QuerySettingsDto; use App\Dto\Builder\DocumentationVersion as DocumentationVersionBuilderDto; use App\Dto\Service\Admin\Project\DocumentationVersion\StoreUpdate; -use App\Enums\CacheTag; use App\Enums\DocumentationVersionStatus; use App\Models\DocumentationVersion; use App\Models\User; @@ -141,7 +140,7 @@ final class DocumentationVersionService extends Service $dataVersion = $this->getDataVersion($data); return $this->documentationVersionCommandHandler->handleStore($project, $dataVersion); }); - $this->clearCacheCommandHandler->byTag(CacheTag::DocumantationVersion); + $this->clearCacheCommandHandler->all(); } catch (\Throwable $e) { report($e); return $this->errService(__('Server Error')); @@ -178,7 +177,7 @@ final class DocumentationVersionService extends Service $dataVersion = $this->getDataVersion($data); return $this->documentationVersionCommandHandler->handleUpdate($version, $dataVersion); }); - $this->clearCacheCommandHandler->byTag(CacheTag::DocumantationVersion); + $this->clearCacheCommandHandler->all(); } catch (\Throwable $e) { report($e); return $this->errService(__('Server Error')); @@ -207,7 +206,7 @@ final class DocumentationVersionService extends Service DB::transaction(function () use ($version) { $this->documentationVersionCommandHandler->handleDestroy($version); }); - $this->clearCacheCommandHandler->byTag(CacheTag::DocumantationVersion); + $this->clearCacheCommandHandler->all(); } catch (\Throwable $e) { report($e); return $this->errService(__('Server Error')); diff --git a/app/application/app/Services/Admin/Project/TranslationService.php b/app/application/app/Services/Admin/Project/TranslationService.php index 2a3d6fd..fabd3de 100644 --- a/app/application/app/Services/Admin/Project/TranslationService.php +++ b/app/application/app/Services/Admin/Project/TranslationService.php @@ -5,7 +5,6 @@ namespace App\Services\Admin\Project; use App\Dto\Service\Admin\Project\Translation\Translations; use App\Dto\Service\Admin\Project\Translation\Translation; use App\Dto\Service\Admin\Project\Translation\Update; -use App\Enums\CacheTag; use App\Jobs\Translate\ProcessTranslationText; use App\Models\ProjectTranslation; use App\Models\User; @@ -83,7 +82,7 @@ final class TranslationService extends Service DB::transaction(function () use ($data, $project, $language) { $this->translationModelSyncCommand->execute($project, $language, $data->getTranslations()); }); - $this->clearCacheCommandHandler->byTag(CacheTag::ProjectTranslation); + $this->clearCacheCommandHandler->all(); if (\config('translation_service.enable', false)) { $this->translateContent($projectId, $languageId, $data); } diff --git a/app/application/app/Services/Admin/ProjectService.php b/app/application/app/Services/Admin/ProjectService.php index b31bdc0..b4e5245 100644 --- a/app/application/app/Services/Admin/ProjectService.php +++ b/app/application/app/Services/Admin/ProjectService.php @@ -5,7 +5,6 @@ namespace App\Services\Admin; use App\Dto\Builder\Project as ProjectBuilderDto; use App\Dto\QuerySettingsDto; use App\Dto\Service\Admin\Project\StoreUpdate; -use App\Enums\CacheTag; use App\Enums\Morph; use App\Models\Project; use App\Models\ProjectLanguage; @@ -134,7 +133,7 @@ final class ProjectService extends Service return $project; }); - $this->clearCacheCommandHandler->byTag(CacheTag::Project); + $this->clearCacheCommandHandler->all(); } catch (\Throwable $e) { report($e); return $this->errService(__('Server Error')); @@ -177,7 +176,7 @@ final class ProjectService extends Service return $project; }); - $this->clearCacheCommandHandler->byTag(CacheTag::Project); + $this->clearCacheCommandHandler->all(); } catch (\Throwable $e) { report($e); return $this->errService(__('Server Error')); @@ -202,7 +201,7 @@ final class ProjectService extends Service DB::transaction(function () use ($project) { $this->projectCommandHandler->handleDestroy($project); }); - $this->clearCacheCommandHandler->byTag(CacheTag::Project); + $this->clearCacheCommandHandler->all(); } catch (\Throwable $e) { report($e); return $this->errService(__('Server Error')); diff --git a/app/application/app/Services/ClearCacheCommandHandler.php b/app/application/app/Services/ClearCacheCommandHandler.php index 2d00ded..409be87 100644 --- a/app/application/app/Services/ClearCacheCommandHandler.php +++ b/app/application/app/Services/ClearCacheCommandHandler.php @@ -2,12 +2,12 @@ namespace App\Services; -use App\Enums\CacheTag; +use Illuminate\Support\Facades\Cache; final readonly class ClearCacheCommandHandler { - public function byTag(CacheTag $tag): void + public function all(): void { - $tag->getCache()->flush(); + Cache::flush(); } } diff --git a/app/application/app/Services/Site/DocumentationService.php b/app/application/app/Services/Site/DocumentationService.php index 1c9bfaf..5cbe96f 100644 --- a/app/application/app/Services/Site/DocumentationService.php +++ b/app/application/app/Services/Site/DocumentationService.php @@ -3,7 +3,6 @@ namespace App\Services\Site; use App\Dto\Service\Site\Documentation; -use App\Enums\CacheTag; use App\Enums\DocumentationVersionStatus; use App\Models\DocumentationCategory; use App\Models\Documentation as ModelDocumentation; @@ -22,6 +21,7 @@ use App\Dto\Builder\Documentation as DocumentationBuilderDto; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Cache; final class DocumentationService extends Service { @@ -37,8 +37,7 @@ final class DocumentationService extends Service if ($user?->cannot('viewAny', DocumentationVersion::class)) { $isPublic = 1; } - $version = CacheTag::DocumantationVersion->getCache() - ->remember(self::class . $project->id . '_' . $isPublic ?? 0, $seconds, function () use ($project, $isPublic) { + $version = Cache::remember(self::class . $project->id . '_' . $isPublic ?? 0, $seconds, function () use ($project, $isPublic) { $versions = $project->documentationVersions() ->when($isPublic, function (Builder $query) { $query->where('is_public', 1); diff --git a/app/application/app/View/Components/Site/ChooseLanguage.php b/app/application/app/View/Components/Site/ChooseLanguage.php index 17c78b5..906281c 100644 --- a/app/application/app/View/Components/Site/ChooseLanguage.php +++ b/app/application/app/View/Components/Site/ChooseLanguage.php @@ -2,9 +2,9 @@ namespace app\View\Components\Site; -use App\Enums\CacheTag; use App\Models\Project; use App\Services\WebsiteTranslations; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Str; use Illuminate\View\Component; use Illuminate\View\View; @@ -24,7 +24,7 @@ final class ChooseLanguage extends Component } $seconds = 3600 * 12; - $languages = CacheTag::Project->getCache()->remember(self::class . $this->project->id, $seconds, function () { + $languages = Cache::remember(self::class . $this->project->id, $seconds, function () { return $this->project->languages; }); diff --git a/app/application/app/View/Components/Site/ChooseVersion.php b/app/application/app/View/Components/Site/ChooseVersion.php index e2f63fb..8552e2f 100644 --- a/app/application/app/View/Components/Site/ChooseVersion.php +++ b/app/application/app/View/Components/Site/ChooseVersion.php @@ -2,13 +2,12 @@ namespace App\View\Components\Site; -use App\Enums\CacheTag; use App\Models\DocumentationVersion; use App\Models\Project; use App\Models\User; use App\Services\WebsiteTranslations; use Illuminate\Database\Eloquent\Builder; -use Illuminate\Support\Str; +use Illuminate\Support\Facades\Cache; use Illuminate\View\Component; use Illuminate\View\View; @@ -29,8 +28,7 @@ final class ChooseVersion extends Component } $seconds = 3600 * 12; - $versions = CacheTag::DocumantationVersion->getCache() - ->remember(self::class . $this->project->id . '-' . $isPublic ?? 0, $seconds, function () use ($isPublic) { + $versions = Cache::remember(self::class . $this->project->id . '-' . $isPublic ?? 0, $seconds, function () use ($isPublic) { return $this->project->documentationVersions() ->when($isPublic, function (Builder $query) { $query->where('is_public', 1);