简体   繁体   中英

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:

  • Server content caching

  • Server file caching

  • Client caching

  • Output caching

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?

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.

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 eg 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM