TYPO3: what are the different kind of caches? - caching

In the TYPO3 backend, I can clear different kinds of cache: frontend caches, general caches, system caches... Furthermore, there are also options to clear caches in the install tools.
In many cases, especially when I develop an extension, I need to clear the caches to reflect the changes I made. However, I never really know which caches I need to clear, and most of the time, I clear each one until I saw the right output when reloading the page. In other cases, when I upgrade TYPO3 for instance, I need to clear the caches from the Install tools, otherwise it looks for php files in the old installation path.
What are the different kind of caches that can be cleared? What is the difference between each of them? Which files or database items each command clears? In which case each clear caches command is necessary (i.e. when modifying which kind of file or information)?

In TYPO3 6.2 and 7:
You can see the configuration of all caches in the backend System > Configuration in the SYS.caching.cacheConfiguration section. Every cache is registered in one or more "groups": all, system, pages. The menu items reflect these groups:
"Flush frontend caches" (cacheCmd=pages): Clears frontend and page-related caches. This makes TYPO3 re-render content which is usually cached (everything except USER_INT objects)
"Flush general caches" (cacheCmd=all): Includes frontend, plus some caches registered by extensions with clearAllCache_additionalTables (i.e. news cache, realurl caches). Despite being all it does not include the system caches (and this is why it is called "general caches" and not "all caches" in the menu).
"Flush system caches" (cacheCmd=system): Clears "system-related caches", including the class loader, localization and extension configuration file caches.
Install tool "Clear all caches": This is a hardwired to "remove all typo3temp/var/Cache files", and also all MySQL cache-tables ("cf_*", i.e. Extbase Reflection). Then it goes through all registered Caches and clears them all too.
So best is to get yourself aware what parts of your code are stored in which cache so that you understand what to flush when you change something:
PHP classes in Extbase have their content parsed in so called "Reflection Cache" (i.e. the annotations) => Flush system cache.
You extension settings ext_tables.php, ext_localconf.php, TCA are cached in the cache_core => Flush system cache.
Your fluid templates are compiled into PHP code => Flush system cache.
Your PHP code might be cached by the "opcache" of your PHP. Usually opcaches are configured to check for the modification time of the file, so usually you don't need to flush any opcache after modifying PHP files. This might not be the case in some scenarios, or if there you work through symlinks of the system time is not synchronized, then you might need to flush opcache after PHP code change => Install tool clear all cache.
Your TypoScript is also cached (cache_hash) => Flush frontend caches. Note that if you change TypoScript in the backed, this will automatically flush these caches automatically.
If your change will also affect the cached output that is rendered to the frontend, you might also need to Flush frontend cache. To avoid this you might set in your TypoScript: config.no_cache = 1.
Please note that since TYPO3 8.1 the menu in the backend and the whole system has been simplified, so we only have left:
"Flush frontend caches": Clears frontend and page-related caches, like before.
"Flush all caches": Does more or less what the install tool previously did. This will thus include also all extension caches, reflection, system caches. Since it includes the "opcache flushing", also PHP file changes would be reflected here.
To ease development without caring about some of these caches, you might want to turn them individually "off".
$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['cache_pages']['backend'] = NullBackend::class;
$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['cache_pagesection']['backend'] = NullBackend::class;
$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['cache_hash']['backend'] = NullBackend::class;
$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['extbase_object']['backend'] = NullBackend::class;
$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['extbase_reflection']['backend'] = NullBackend::class;
See: https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/CachingFramework/Configuration/Index.html?highlight=cache#how-to-disable-specific-caches

In very general you need to clear frontend and general caches when changes made in the record (by editing) aren't reflected on page (because page is cached).
system cache additionally keeps different configurations from extensions (all these stuff from ext_tables.php, ext_localconf.php, language files, etc.) so you need to clear it when doing changes in these files... but also when injecting for an example new repository to the controllers.
TIP: there's some plugins for the browsers which displays cache clearing icon (a.k.a. Yellow Flash) in the address bar, i.e.: TYPO3 Clear Cache for Chrome

as noone mentioned the files yet:
there are a lot of temporary files which could be removed anytime, and must be removed sometimes. partially they even are included in the cache clearing from the BE.
the base folder is /typo3temp/
caching is done in /typo3temp/Cache/ which is divided in /typo3temp/Cache/Code/ and /typo3temp/Cache/Data/
here are gathered the concatenation of some php-files (e.g. ext_tables.php)
since 7LTS there is another folder which needs manual deletion sometimes: typo3temp/autoload/ where class-information is stored for autoloading. Especially if you develop new extensions this folder is not cleared automatically on each edit.

Related

Clearing cached system settings on modx revolution

I have a snippet that updates some system settings by updating and saving modSystemSetting objects. I noticed that old settings are still coming from the cache.
Clearing the cache works:
$cacheManager = $modx->getCacheManager();
$cacheManager->clearCache();
But this clears the whole cache which isn't good. How could I clear only updated settings? Clearing all systems settings would work too.
Checkout the refresh function in modcachemanager.class.php, look at each of the $providers.
For system-settings try to start with $cacheManager->generateConfig() and see from there. Maybe you'd need more then just the system settings, like context settings, etc..
If you go further, checkout using custom cache. You can delete specific keys in the cache $cacheManager->delete($key). See the Programmatic (Custom) Caching

Benefit of disabling cache over enabling when coding

On the, The Net Ninja Youtube channel I see the Ninja has disabled cache in his Laravel 6 tutorial. Just curious what's the benefit over enabling when coding?
So that changes made to resources loaded into the page, such as images, stylesheets, and scripts are always refreshed and reloaded when the page itself is reloaded (so you don't need to remember to press Shift+F5 or Ctrl+Shift+R).
When caching is enabled the browser may prefer its cached versions which may be stale instead of always using the latest-built assets.
However disabling caching is unnecessary if you use a content-addressing scheme for off-page resources (i.e. the URI of a script file or stylesheet includes its content hash (SHA-256, etc)).

Cache management and Index management in magento

Why it is sometime necessary to do Cache management to disable and Index management to re-index in magento.I am new in magento so if you know then reply this kindly.
In your development environment its advised to disable the cache because you tend to make the changes in the template / layout files often so to get it reflected on the frontend / website you are advised to disable the cache in your development environment. But don't do it in PRODUCTION.
And coming to Index Management, set it as "Save on Update" mode so that each time if you make some changes to your products, categories or attributes its getting re-indexed automatically and avoids the necessity to re-index it every time manually.
Specifically, "Block" data are the html blocks that the MVC generates to present to the frontend and even in the admin sometimes. Because of the caching and also session information, you need to log out of admin and back in for some changes to appear.
Depending on site volume, there might not be a penalty for turning off caching. If I'm doing a quick styling fix, I'll disable the block cache for a couple minutes.

cache manifest uncache

Now that I've successfully cached my web page, how do I uncache it after making a change?
My user can't dl the latest version, even after I've changed a comment in my cache.manifest file.
My server is an IIS server.
The thing with caching is, well, stuff gets cached. Browsers won't, in general, try to download anything you've told them to cache until the cached items expire.
If you set everything to cache for a certain time span, the browser won't try to download any of the cached items until the end of it, which includes the cache.manifest file itself, by the sound of it.
Typically, you don't want to cache the content of the website, because then that makes it hard to change. Instead, you want to cache the various pieces, like images, css, and javascript, that the various pages of your site need. If you do this right, you can get a huge benefit for your users, and still have control over those resources, since you can always link to a different version of a particular resource in the content of the pages.
That said, if you do need to cache some portions of your pages, you can use server-side caching to reuse portions that are expensive to put together.

Magento - APC Caching, weird basket behaviour

Has anyone ever noticed any weird behaviour with regards to the shopping cart in magento when apc caching is enabled?
I have a situation where it looks as though extra items and/or different items are being added when the user adds something.
Its very strange and aparantly random but only seems to occur when we have apc enabled.
This answer touches on what might be going on:
Memcached vs APC which one should I choose?
Simply move to memcache and your troubles should be resolved.
You may want to try and clear APC's cache, both system cache and user cache.
Note that there is a difference between regular APC cache from CLI and Web based entries, and from what I've gathered you can't simply call it from CLI it has to be from a web request like so:
system('wget --spider --quiet http://localhost/apc/clear_apc_cache.php');
clear_apc_cache.php would contain:
apc_clear_cache('user');
More details:
http://php.net/manual/en/function.apc-clear-cache.php
and note the Cache type Parameter:
If cache_type is "user", the user
cache will be cleared; otherwise, the
system cache (cached files) will be
cleared.

Resources