Umbraco“GetContentByTag”方法缓存问题

时间:2016-02-25 10:50:50

标签: c# asp.net-mvc umbraco umbraco7

我尝试以编程方式将标记添加到文档中:

var cs = ApplicationContext.Current.Services.ContentService;

var item = cs.GetById(1227);
item.SetValue("itemTags", "testTagName");

cs.SaveAndPublishWithStatus(item);
cs.RePublishAll();    
umbraco.library.RefreshContent();

在另一个页面中,我需要按标签过滤项目:

var filteredItemsByTag = Umbraco.TagQuery.GetContentByTag("testTagName");

但是这种方法仍然没有返回上面添加的项目。仅当我从admin backoffice“保存并发布”当前项目时才有效。

我在Umbraco.Core中看到“GetContentByTag”方法从RuntimeCacheProvider获取值,该方法具有“Clear()”方法,但类是内部的,所以我不能使用它。

有没有办法获得物品?

由于

1 个答案:

答案 0 :(得分:0)

首先你不需要打电话:

cs.RePublishAll(); 
umbraco.library.RefreshContent();

使用此方法按标记获取节点 - ApplicationContext.Services.TagService.GetTaggedContentByTag("tag");