V
V
Victoria Erofeeva2020-05-17 18:22:25
1C-Bitrix
Victoria Erofeeva, 2020-05-17 18:22:25

Why doesn't CPHPCache caching work?

Help me understand why caching to the InitCache methods of the CPHPCache class does not work. I tried to cache the output of the list of infoblocks from the database, but I noticed that caching does not work at all. More precisely, the InitCache method does not work. It always returns false What could be the reason?

Here I have a very simple code to check the operation of the caching class, it shows that caching is not happening.

$cache_id = serialize($arParams); 
$obCache = new CPHPCache; 

if ($obCache->InitCache(3600, $cache_id, '/')) { // тянем данные если они есть
   $arResult = $obCache->GetVars(); 
} 
elseif ($obCache->StartDataCache()) { // иначе запишем для того, чтобы следующий раз получить 
   $arResult = rand(0,100);  
   $obCache->EndDataCache($arResult); 
} 

var_dump($arResult);


var_dump($arResult) always returns different values ​​even though it should return the first cached random number! $obCache->InitCache always returns false

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2020-05-17
@webdefvika

Change the third parameter (instead of / the name of the 'randnumbers' directory). Here is the dock in more detail: https://dev.1c-bitrix.ru/api_d7/bitrix/main/data/c...
Disabled component caching. If you have the cache in the component enabled, then there is no point in additional caching inside.
Make sure you don't have ?clear_cache=Y in your request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question