E
E
Evgeny Nikolaev2019-06-05 13:58:29
1C-Bitrix
Evgeny Nikolaev, 2019-06-05 13:58:29

Bitrix find out what cache file was used to generate the page? Is it possible to clear the cache of a component for a specific user via api?

/!\ I specified the 1C-Bitrix and Caching tags for the question, if the question does not apply to the second tag, please delete it.
The question is asked in order to find approaches to the development of bitrix with reasonable cache management, so there is no need to limit the answers to it to a specific task.
There is an online store on bitrix in it a catalog. When displaying the main section of the catalog, a component is called that calls others inside itself, so it comes to the output of a specific product (to display the html of each product, the catalog.item component is called). I am writing all this to make it clear that the components are called inside another along the chain, so dynamic data can be cached above the component in which they are requested from the database.
In particular, there is a self-written library for displaying likes on products (the code is here, although it has nothing to do with the question - blog.ivru.net/?id=49 )
So when you click on the like, the request goes to the api and changes the status of the like (installed removed), but when the catalog page is reloaded, the information is not displayed, since the cache of the parent component is displayed and the catalog.item component simply does not reach the request for information in the result-modifier.php file.
There is such a moment, in fact, I can reset the cache in the file that ajax goes to to change the state. For example BXClearCache(true, "/s1/bitrix/catalog.section/"); (tested works), only this request will clear the cache of the entire catalog.section, including other users whose information could continue to be loaded from the cache.
The following questions are of interest:
1) is it possible to get the name of the cache file from which the page was loaded in the process of work? Then I would just delete that particular file.
2) are there mechanisms for managing the cache of the component tied to the user? (I mean, if the user's session is suddenly enough to manage exactly his cache, then in the ajax request I would not even need to pass the address of the cache file, if everything necessary is in sessions).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
serginhold, 2019-06-05
@serginhold

All you need to do is not cache those likes, if that's what the user has in mind for favorites. Otherwise, you'll just be caching dofiga of the same information, where the difference is only in the user ID.
and if the number of likes is meant, i.e. 10 users clicked, and the number 10 is displayed next to the button, then you need to clear the cache by key. In general, you just need to know this key, or folder.
You create a cache object, \Bitrix\Main\Data\Cache::createInstance(), and there are cleanup methods.
The cache key in standard components usually depends on the path in the address bar. Although I could look at the source myself ..
In any case, the easiest way is to create your own component with this button, and even if there is some kind of cache in it, connect this component bypassing the general cache of the page / product.

R
Roman Gritsuk, 2019-06-06
@winer

If you have a cache for each user, then something went wrong. Such a cache will only eat up disk space and most likely there will be no performance gain.
Everything related to displaying user-specific elements: comparison buttons, shopping cart buttons, wish lists, etc. - then it's better to load all this through ajax. This way you can give the page to the user faster.
About clearing the cache. There are a lot of classes for working with cache in Bitrix. Where and what is used can be said only by looking at the source code of the component . There is also no single standard for generating cache keys.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question