YRuth
YRuth

Reputation: 1

Kentico 9 - Data cache Macro

I'm doing the field validation on the custom table. This is the macro on the validation field:

{% 
	foreach (i IN CMSContext.Current.GlobalObjects.CustomTables["customtable"].Items.ItemsAsFields.IdNumber) 
	{
			if (i == IdNumber.Value){
				return false;
			} 
	}
		return true;
	#%}

The issue start from this part of the macro : CMSContext.Current.GlobalObjects.CustomTables["customtable"].Items.ItemsAsFields.IdNumber

This line of macro should get all the data entered in my customtable, however it didn't get recent ones. In this case my validation won't work and I will keep entering the same IdNumber.

This is the way how I found out, when I ran this macro via System - Macro - Benchmark : {%CMSContext.Current.CMSContext.Current.CMSContext.Current.GlobalObjects.CustomTables["customtable"].Items.ItemsAsFields.ItemID #%}

I tested "Clear Cache", this worked. So it seems to me cache issue.
So I have turned off all of the cache in Setting - System - Performance:

and yet, that line of macro not returning the latest data when I entered new data.

Is there any way to clear cache using macro or other option to solve this problem?

Upvotes: 0

Views: 167

Answers (2)

Boris P.
Boris P.

Reputation: 415

I think this is the cause of your issue (hotfix 9.0.46):

Custom tables - Custom table Items collection incorrectly cached in macros
When using the Items property of custom table objects in macros, the data was incorrectly cached. For example, when using the 'GlobalObjects.CustomTables["<customtablecodename>"].Items' macro, the latest data was not returned.

Upvotes: 1

rocky
rocky

Reputation: 7696

Neither the output nor the data cache is applied on macros (you can optionally manually turn it on but it's off by default).

There is an extra level of caching which is not visible to the user - the API-level hashtables. Kentico takes care of updating the tables automatically whenever an object is changed via the API. So there are basically two options of what can go wrong: - either there is a bug in the hashtables - or you're not updating the custom table via the API but e.g. via a direct SQL query and the system is unaware of changes made to the database

The question is: Are you using a SQL query?

If you are, you have to flush the cache manually by calling ClearHashtables.

Upvotes: 0

Related Questions