|
| 1 | +<?php namespace App\libs\Utils\Doctrine; |
| 2 | +/* |
| 3 | + * Copyright 2025 OpenStack Foundation |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + * See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + **/ |
| 14 | + |
| 15 | +use Illuminate\Contracts\Cache\Factory; |
| 16 | +use Illuminate\Support\ServiceProvider; |
| 17 | +use LaravelDoctrine\ORM\Configuration\Cache\CacheManager; |
| 18 | +use LaravelDoctrine\ORM\Configuration\Cache\RedisCacheProvider; |
| 19 | + |
| 20 | +class CustomRedisCacheProvider extends RedisCacheProvider |
| 21 | +{ |
| 22 | + |
| 23 | + /** |
| 24 | + * CustomRedisCacheProvider constructor. |
| 25 | + */ |
| 26 | + public function __construct(protected Factory $cache) |
| 27 | + { |
| 28 | + parent::__construct($cache); |
| 29 | + $this->store = null; |
| 30 | + } |
| 31 | +} |
| 32 | +/** |
| 33 | + * Class DoctrineCacheServiceProvider |
| 34 | + * @package App\libs\Utils\Doctrine |
| 35 | + */ |
| 36 | +class DoctrineCacheServiceProvider extends ServiceProvider |
| 37 | +{ |
| 38 | + public function register() |
| 39 | + { |
| 40 | + $this->app->resolving(CacheManager::class, function (CacheManager $cache) { |
| 41 | + // Override the 'redis' driver |
| 42 | + $cache->extend('redis', function (array $settings, $app) { |
| 43 | + $res = new CustomRedisCacheProvider($app->make(Factory::class)); |
| 44 | + return $res->resolve($settings); |
| 45 | + }); |
| 46 | + }); |
| 47 | + } |
| 48 | +} |
0 commit comments