I can understand that the Prefetch cache is very useful for caching items in the database - thereby reducing reads to the SQL server. I can also understand the HTML cache is useful for caching the end result of a rendered component - thereby greatly improving performance. I would like to know what kind of benefit the Item and Data caches give? They seem very similar to me and I'm wondering if they are both needed - or are they just consuming memory for little gain?
3 Answers
Data Cache - Data caches store data from all the data providers defined for the database. The cache contains items of the Sitecore class “ItemInformation”, pulled from the database whenever they are requested.
The data is pulled from the Prefetch cache, if it presents there; else it is pulled out of the database, put into the Prefetch cache and into then the data cache.
The purpose of this cache is to minimise the number of requests to the database. This is extremely important for performance, as requesting items from the database is rather expensive. The maximum size of the Data cache can be configured.
Item Cache - Item caches contain objects of the Sitecore class “Sitecore.Data.Items.Item” that are used in the code most of the time.
The items are built from the “ItemInformation” objects in the data cache, hence, are dependent on database data caches. So, if we request an item, which isn’t present in the item cache, it will get it from the data cache and then populate it in the item cache as an Item.
The reason for this cache is to gain performance so the ItemInformation objects don’t need to get parsed into an Item each time they are requested.
Hope above information will help.
-
1Thanks for this explanation. I ran some tests on a page that was hitting a lot of items (10k items). All caches enabled as normal - 10s load time. Disabling both Item and Data cache - 25s load time. Disabling just Data cache - 20s load time. Disabling just Item cache - 12s load time. So Item cache does have some small benefit worth the memory usage from that test. Commented Apr 23, 2020 at 23:52
-
Happy that you liked my answer. That's true, these Sitecore caching make impact in page performance.,– AB1005Commented Apr 26, 2020 at 21:52
Some further details not mentioned in AB1005's answer:
Data Cache
The data cache keeps track of item ID's that result in no item found. It refers to these as NullItems. Whereas the prefetch cache will simply not add an entry if it is not found. This prevents unnecessary database calls for know nulls.
This means that if you hit a Sitecore website with /?sc_itemid={aValidRandomGuid}
it will add every entry to the data cache. The result is a very tiny allocation- in the tune of bytes only.
Also- the data cache (as well as the prefetch cache) contains all immediate data for an item including all: versions, languages, shared fields, versioned fields and unversioned fields. Be aware that this isn't truly ALL the data for the item (standard values, default value, etc), but the data that is most readily accessible on a trip to the database. Items in this cache are referenced by ID.
Item Cache
In addition to the items in this cache being fully implement objects of type Item
as mentioned, they are also stored as a combination of "ItemID+Language+Version". This means that once an item is pulled from the database any additional versions and languages are pulled from the data cache and each receives a unique entry in the item cache.
The ItemCache caches the Item itself, with all of the fields and associated information. It allows for faster retrieval when you call GetItem or when Items are resolved in pipelines such as HttpRequest so that there aren't constant database queries.
The DataCache caches Information about the an item, such as the item's Child ID's, the languages and versions, the parent, and information surrounding the template.