我正在对自定义表进行字段验证。这是验证字段上的宏:
{%
foreach (i IN CMSContext.Current.GlobalObjects.CustomTables["customtable"].Items.ItemsAsFields.IdNumber)
{
if (i == IdNumber.Value){
return false;
}
}
return true;
#%}
问题从宏的以下部分开始: CMSContext.Current.GlobalObjects.CustomTables"customtable".Items.ItemsAsFields.IdNumber
这一行宏应该获取我自定义表中输入的所有数据,但是它没有得到最近的数据。在这种情况下,我的验证不能工作,我将继续输入相同的IdNumber。
当我通过:{%CMSContext.Current.CMSContext.Current.CMSContext.Current.GlobalObjects.CustomTables"customtable".Items.ItemsAsFields.ItemID #%}运行这个宏时,我就是这样发现的。
我测试了“清除缓存”,这起作用了。所以在我看来缓存问题。
因此,我在设置系统性能时关闭了所有缓存:
然而,当我输入新数据时,这一行宏没有返回最新数据。
是否有任何方法来清除缓存使用宏或其他选项来解决这个问题?
发布于 2017-09-22 01:03:54
我认为这就是你问题的原因(热修复 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.发布于 2017-09-21 11:36:19
输出和数据缓存都不应用于宏(您可以选择手动把它打开,但默认情况下是关闭的)。
还有一个额外的缓存级别对用户是不可见的-API级别的哈希表。当通过API更改对象时,Kentico负责自动更新表。因此,基本上有两种可能出错的选项:或者哈希表中有错误,或者您不是通过API更新自定义表,而是通过一个直接的SQL查询来更新自定义表,并且系统不知道对数据库所做的更改。
问题是:您在使用SQL查询吗?
如果是,则必须通过调用ClearHashtables手动刷新缓存。
https://stackoverflow.com/questions/46329304
复制相似问题