B
B
bitrix0ID2019-08-08 11:02:50
1C-Bitrix
bitrix0ID, 2019-08-08 11:02:50

What's wrong with caching?

Clarify about the cache, please. Here I need to cache some variable (array). I do it like this:

$cache = Cache::createInstance();

if ($cache->initCache(7200, 'mycache'))
    $result = $cache->getVars();
else {
    $result = ['key' => 'value'];
    $cache->endDataCache($result);
}

I understand it this way: in the "if" block, the presence of a cache with the specified name is checked, and if it is, we get a variable in result; in "else" (if there is no cache) - fill in the same result variable and add it to the cache. Further on the code we use result as we need.
I make changes to the result ("else" block), refresh the page, and the changes are immediately displayed, which means that the cache has not been saved. And "cache->initCache()" returns "false". What did I miss?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-08-08
@bitrix0ID

Try:
elseif ($cache->startDataCache()) {

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question