44 'adapter_callback' =>
'',
46 'data_table_callback' =>
'',
48 'tags_table_callback' =>
'',
50 'infinite_loop_flag' =>
false,
66 if (empty($this->_options[
'adapter_callback'])) {
67 if (!$this->_options[
'adapter'] instanceof \
Magento\Framework\DB\Adapter\AdapterInterface) {
69 'Option "adapter" should be declared and extend \Magento\Framework\DB\Adapter\AdapterInterface!' 73 if (empty($this->_options[
'data_table']) && empty($this->_options[
'data_table_callback'])) {
76 if (empty($this->_options[
'tags_table']) && empty($this->_options[
'tags_table_callback'])) {
88 if (!$this->_connection) {
89 if (!empty($this->_options[
'adapter_callback'])) {
96 'DB Adapter should be declared and extend \Magento\Framework\DB\Adapter\AdapterInterface' 112 if (empty($this->_options[
'data_table'])) {
114 if (empty($this->_options[
'data_table'])) {
118 return $this->_options[
'data_table'];
128 if (empty($this->_options[
'tags_table'])) {
130 if (empty($this->_options[
'tags_table'])) {
134 return $this->_options[
'tags_table'];
146 public function load(
$id, $doNotTestCacheValidity =
false)
148 if ($this->_options[
'store_data'] && !$this->_options[
'infinite_loop_flag']) {
149 $this->_options[
'infinite_loop_flag'] =
true;
153 )->where(
'id=:cache_id');
155 if (!$doNotTestCacheValidity) {
156 $select->where(
'expire_time=0 OR expire_time>?',
time());
159 $this->_options[
'infinite_loop_flag'] =
false;
174 if ($this->_options[
'store_data'] && !$this->_options[
'infinite_loop_flag']) {
175 $this->_options[
'infinite_loop_flag'] =
true;
182 'expire_time=0 OR expire_time>?',
186 $this->_options[
'infinite_loop_flag'] =
false;
205 public function save(
$data,
$id, $tags = [], $specificLifetime =
false)
208 if (!$this->_options[
'infinite_loop_flag']) {
209 $this->_options[
'infinite_loop_flag'] =
true;
211 if ($this->_options[
'store_data']) {
217 $expire = $lifetime === 0 || $lifetime ===
null ? 0 : $time + $lifetime;
221 $createCol =
$connection->quoteIdentifier(
'create_time');
222 $updateCol =
$connection->quoteIdentifier(
'update_time');
223 $expireCol =
$connection->quoteIdentifier(
'expire_time');
225 $query =
"INSERT INTO {$dataTable} ({$idCol}, {$dataCol}, {$createCol}, {$updateCol}, {$expireCol}) " .
226 "VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE {$dataCol}=VALUES({$dataCol}), " .
227 "{$updateCol}=VALUES({$updateCol}), {$expireCol}=VALUES({$expireCol})";
234 $this->_options[
'infinite_loop_flag'] =
false;
245 public function remove(
$id)
247 if ($this->_options[
'store_data'] && !$this->_options[
'infinite_loop_flag']) {
248 $this->_options[
'infinite_loop_flag'] =
true;
250 $this->_options[
'infinite_loop_flag'] =
false;
275 if (!$this->_options[
'infinite_loop_flag']) {
276 $this->_options[
'infinite_loop_flag'] =
true;
279 case \Zend_Cache::CLEANING_MODE_ALL:
282 case \Zend_Cache::CLEANING_MODE_OLD:
285 case \Zend_Cache::CLEANING_MODE_MATCHING_TAG:
286 case \Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
287 case \Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
294 $this->_options[
'infinite_loop_flag'] =
false;
307 if ($this->_options[
'store_data']) {
347 'COUNT(cache_id)=' . count($tags)
417 $res = [
'expire' =>
$data[
'expire_time'],
'mtime' =>
$data[
'update_time'],
'tags' => $tags];
431 if ($this->_options[
'store_data']) {
434 [
'expire_time' =>
new \
Zend_Db_Expr(
'expire_time+' . $extraLifetime)],
435 [
'id=?' =>
$id,
'expire_time = 0 OR expire_time>' =>
time()]
459 'automatic_cleaning' =>
true,
461 'expired_read' =>
true,
463 'infinite_lifetime' =>
true,
477 if (!is_array($tags)) {
486 $select =
$connection->select()->from($tagsTable,
'tag')->where(
'cache_id=?',
$id)->where(
'tag IN(?)', $tags);
489 $insertTags = array_diff($tags, $existingTags);
490 if (!empty($insertTags)) {
491 $query =
'INSERT IGNORE INTO ' . $tagsTable .
' (tag, cache_id) VALUES ';
494 foreach ($insertTags as $tag) {
499 $query .= implode(
',', $lines);
516 if ($this->_options[
'store_data']) {
520 case \Zend_Cache::CLEANING_MODE_MATCHING_TAG:
521 $select->where(
'tag IN (?)', $tags)->group(
'cache_id')->having(
'COUNT(cache_id)=' . count($tags));
523 case \Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
524 $select->where(
'tag NOT IN (?)', $tags);
526 case \Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
527 $select->where(
'tag IN (?)', $tags);
538 while (
$row = $stmt->fetch()) {
539 $ids[] =
$row[
'cache_id'];
541 if ($counter > 100) {
564 if ($this->_options[
'store_data']) {
581 if ($this->_options[
'store_data']) {
584 [
'expire_time> ?' => 0,
'expire_time<= ?' =>
time()]
call_user_func($callable, $param)
getIdsMatchingTags($tags=[])
_cleanByTags($mode, $tags)
save($data, $id, $tags=[], $specificLifetime=false)
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
static throwException($msg, Exception $e=null)
clean($mode=\Zend_Cache::CLEANING_MODE_ALL, $tags=[])
load($id, $doNotTestCacheValidity=false)
getIdsNotMatchingTags($tags=[])
getIdsMatchingAnyTags($tags=[])
touch($id, $extraLifetime)
getLifetime($specificLifetime)