T
T
Timur Kalimullin2016-07-22 21:08:58
PHP
Timur Kalimullin, 2016-07-22 21:08:58

How to correctly call the function with the CPHPCache cache in 1C-Bitrix several times with clear_cache?

Good afternoon,
I cache data from the 1C-Bitrix database using the standard class from the CPHPCache box.
Simple procedural approach.

function myCache()
{
  $obCache 	= new CPHPCache();
  $arResult 	= array();

  if($obCache->InitCache(36000000, 'myCache', '/myCache/'))
  {
    $vars = $obCache->GetVars();
    $arResult = $vars['arResult'];
  }
  elseif($obCache->StartDataCache())
  {
    /* запросы к бд */
    
    $obCache->EndDataCache(array('arResult' => $arResult));
  }
  return $arResult;
}

This function "myCache" contains parameters that are used in other functions for processing data. Those. myCache can be called 5-10-15 times in different places.
The problem occurs after the "clear_cache=Y" cache flush occurs.
The database is accessed as many times as the function is called.
According to the idea, during the subsequent call to the "myCache" function, the cache should have been reset 1 time, after giving data from the cache. But apparently the presence of the variable "clear_cache=Y" completely excludes the creation of a cache.
Is there a way to avoid constantly flushing the cache when get "clear_cache=Y" is present?
Creating a class and working with "myCache" within an instance is an option, but there may be another solution...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Harakhnin, 2016-07-26
@Chupokabr

You don't seem to understand why the clear_cache variable is in Bitrix. This essentially guarantees that the page will not use the cache. Why bypass it? Of course, you can make your cache and not react to this variable, but then how will you reset it? Create your own custom_clear_cache type variable and what will change except that you will subsequently explain to all developers that you have come up with such a cool bike

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question