| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
5 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
6 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
7 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
8 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
9 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
10 |
* THE SOFTWARE.
|
|
|
11 |
*
|
|
|
12 |
* This software consists of voluntary contributions made by many individuals
|
|
|
13 |
* and is licensed under the MIT license.
|
|
|
14 |
*
|
|
|
15 |
* Copyright (c) 2014-2022 Yuuki Takezawa
|
|
|
16 |
*
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
declare(strict_types=1);
|
|
|
20 |
|
|
|
21 |
namespace Ytake\LaravelSmarty\Cache;
|
|
|
22 |
|
|
|
23 |
use Ytake\LaravelSmarty\Smarty;
|
|
|
24 |
use Illuminate\Contracts\Config\Repository as ConfigContract;
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Class Storage
|
|
|
28 |
*
|
|
|
29 |
* @author yuuki.takezawa<yuuki.takezawa@comnect.jp.net>
|
|
|
30 |
* @license http://opensource.org/licenses/MIT MIT
|
|
|
31 |
*/
|
|
|
32 |
class Storage
|
|
|
33 |
{
|
|
|
34 |
/**
|
|
|
35 |
* @param Smarty $smarty
|
|
|
36 |
* @param ConfigContract $repository
|
|
|
37 |
*/
|
|
|
38 |
public function __construct(
|
|
|
39 |
protected Smarty $smarty,
|
|
|
40 |
protected ConfigContract $repository
|
|
|
41 |
) {
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
*/
|
|
|
46 |
public function cacheStorageManaged(): void
|
|
|
47 |
{
|
|
|
48 |
$driver = $this->repository->get('ytake-laravel-smarty.cache_driver', 'file');
|
|
|
49 |
if ($driver !== 'file') {
|
|
|
50 |
$storage = $driver . "Storage";
|
|
|
51 |
$this->smarty->registerCacheResource($driver, $this->$storage());
|
|
|
52 |
}
|
|
|
53 |
$this->smarty->caching_type = $driver;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* @return Redis
|
|
|
58 |
*/
|
|
|
59 |
protected function redisStorage(): Redis
|
|
|
60 |
{
|
|
|
61 |
return new Redis($this->repository->get('ytake-laravel-smarty.redis'));
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
* @return Memcached
|
|
|
66 |
*/
|
|
|
67 |
protected function memcachedStorage(): Memcached
|
|
|
68 |
{
|
|
|
69 |
return new Memcached(
|
|
|
70 |
new \Memcached(),
|
|
|
71 |
$this->repository->get('ytake-laravel-smarty.memcached')
|
|
|
72 |
);
|
|
|
73 |
}
|
|
|
74 |
}
|