2namespace Sale\Handlers\Delivery\Additional;
4use \Bitrix\Main\Application;
5use Bitrix\Main\ArgumentOutOfRangeException;
6use Bitrix\Main\Config\Option;
16 protected $cacheIdBase =
'';
19 protected static $cacheManager =
null;
26 public function __construct(
$type, $ttl)
28 if(static::$cacheManager ===
null)
29 static::$cacheManager = Application::getInstance()->getManagedCache();
31 $this->cacheIdBase = self::createCacheId(
$type);
42 $cacheId = $this->getCacheId($ids);
44 if(static::$cacheManager->read($this->ttl, $this->cacheIdBase))
46 $res = static::$cacheManager->get($this->cacheIdBase);
48 if(!empty(
$res[$cacheId]))
55 public function getAll()
59 if(static::$cacheManager->read($this->ttl, $this->cacheIdBase))
60 $result = static::$cacheManager->get($this->cacheIdBase);
73 if(static::$cacheManager->read($this->ttl, $this->cacheIdBase))
74 $cached = static::$cacheManager->get($this->cacheIdBase);
76 if(!is_array($cached))
79 $cacheId = $this->getCacheId($ids);
80 $cached[$cacheId] =
$value;
82 static::$cacheManager->set($this->cacheIdBase, $cached);
88 public function clean()
90 static::$cacheManager->clean($this->cacheIdBase);
97 protected function getCacheId(
array $ids =
array())
103 foreach (array_keys($ids) as $index)
105 if (is_array($ids[$index]))
107 $ids[$index] = serialize($ids[$index]);
121 protected static function createCacheId(
$type)
123 return 'SALE_HNDL_DELV_ADD_'.$type;
134class CacheSession
extends Cache
136 public function __construct(
$type, $ttl)
138 $this->cacheIdBase = self::createCacheId(
$type);
147 $cacheId = $this->getCacheId($ids);
149 if (!isset($_SESSION[$this->cacheIdBase]))
151 $_SESSION[$this->cacheIdBase] = [];
154 $_SESSION[$this->cacheIdBase][$cacheId] =
$value;
164 $cacheId = $this->getCacheId($ids);
166 if(isset($_SESSION[$this->cacheIdBase][$cacheId]))
167 $result = $_SESSION[$this->cacheIdBase][$cacheId];
177 $cacheId = $this->getCacheId($ids);
178 unset($_SESSION[$this->cacheIdBase][$cacheId]);
188 protected static $items =
array();
191 const TYPE_PROFILES_LIST = 1;
192 const TYPE_DELIVERY_FIELDS = 2;
193 const TYPE_DELIVERY_PRICE = 3;
194 const TYPE_PROFILE_FIELDS = 4;
195 const TYPE_DELIVERY_LIST = 5;
196 const TYPE_PROFILE_CONFIG = 6;
197 const TYPE_EXTRA_SERVICES = 7;
201 const LOC_SESSION = 2;
203 private const DISABLE_CACHE_OPTION =
'hndl_dlv_add_cache_disable';
206 protected static $types =
array(
207 self::TYPE_PROFILES_LIST =>
array(
'TTL' => 2419200,
'LOC' => self::LOC_CACHE),
208 self::TYPE_DELIVERY_FIELDS =>
array(
'TTL' => 2419200,
'LOC' => self::LOC_CACHE),
209 self::TYPE_DELIVERY_PRICE =>
array(
'TTL' => 0,
'LOC' => self::LOC_SESSION),
210 self::TYPE_PROFILE_FIELDS =>
array(
'TTL' => 2419200,
'LOC' => self::LOC_CACHE),
211 self::TYPE_DELIVERY_LIST =>
array(
'TTL' => 2419200,
'LOC' => self::LOC_CACHE),
212 self::TYPE_PROFILE_CONFIG =>
array(
'TTL' => 0,
'LOC' => self::LOC_SESSION),
213 self::TYPE_EXTRA_SERVICES =>
array(
'TTL' => 2419200,
'LOC' => self::LOC_CACHE),
221 public static function getItem(
$type)
223 if(
$type == self::TYPE_NONE)
226 if(empty(self::$types[
$type]))
230 defined(
'SALE_HNDL_DLV_ADD_CACHE_DISABLE')
231 || (
int)Option::get(
'sale', self::DISABLE_CACHE_OPTION, 0) == 1
237 if(empty(self::$items[
$type]))
239 if(self::$types[
$type][
'LOC'] == self::LOC_CACHE)
241 elseif(self::$types[
$type][
'LOC'] == self::LOC_SESSION)
242 self::$items[
$type] =
new CacheSession(
$type, self::$types[
$type][
'TTL']);
245 return self::$items[
$type];
248 public static function cleanAll()
250 foreach(self::$types as $typeId =>
$params)
252 $cache = self::getItem($typeId);
257 public static function getAll()
261 foreach(self::$types as $typeId =>
$params)
263 $cache = self::getItem($typeId);
264 $result[$typeId] = $cache->getAll();
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']