/
mikopbx
/
ModuleSoftphoneBackend
Обзор
Документация
Войти
/
mikopbx
/
ModuleSoftphoneBackend
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
Lib/CacheManager.php
88 строк
3 KB
Портнов Алексей
init
19 янв 2026, 15:47
19 янв 2026, 15:47
0249524
Код
Авторство
О чём код?
<?php /* * MikoPBX - free phone system for small business * Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. * If not, see <https://www.gnu.org/licenses/>. */ namespace Modules\ModuleSoftphoneBackend\Lib; use MikoPBX\Common\Providers\ConfigProvider; use MikoPBX\Core\System\Util; use Modules\ModuleMonitorActiveCalls\Lib\MikoPBXVersion; use Phalcon\Cache\Adapter\Redis; use Phalcon\Storage\SerializerFactory; class CacheManager { public const REDIS_PREFIX = 'ModuleMonitorActiveCalls_'; /** * Возвращает адаптер для подключения к Redis. * @return Redis */ public static function cacheAdapter():Redis { $serializerFactory = new SerializerFactory(); $di = MikoPBXVersion::getDefaultDi(); $options = [ 'defaultSerializer' => 'Php', 'lifetime' => 86400, 'index' => 3, 'prefix' => self::REDIS_PREFIX ]; if($di !== null){ $config = $di->getShared(ConfigProvider::SERVICE_NAME); $options['host'] = $config->path('redis.host'); $options['port'] = $config->path('redis.port'); } return (new Redis($serializerFactory, $options)); } /** * Сохранение кэш в redis * @param $key * @param $value * @param int $ttl * @return void */ public static function setCacheData($key, $value, int $ttl = 86400):void { $cacheAdapter = self::cacheAdapter(); try { $cacheAdapter->set($key, $value, $ttl); }catch (\Throwable $e){ Util::sysLogMsg(self::class, $e->getMessage()); } } /** * Получение данных из кэш * @param $key * @return array */ public static function getCacheData($key):array { $result = []; $cacheAdapter = self::cacheAdapter(); try { $result = $cacheAdapter->get($key); }catch (\Throwable $e){ Util::sysLogMsg(self::class, $e->getMessage()); } return [$result]; } }