【问题标题】:Sitecore - programmatically clear user's cacheSitecore - 以编程方式清除用户的缓存
【发布时间】:2016-04-22 14:49:54
【问题描述】:

我有一个自定义角色提供程序,特定用户的角色可以在他们执行某些操作时更改。

这会导致几个问题:

  1. 如果将角色添加到用户,这将允许他们访问 页面,直到我清除站点核心缓存后才会生效 手动使用/sitecore/admin/cache.aspx

  2. 我们正在缓存用户呈现的菜单栏。但是当权限 更改,可能会添加新项目/删除项目,但这没有反映出来,因为它来自缓存版本。

有没有办法以编程方式清除特定用户的站点核心缓存?

【问题讨论】:

    标签: asp.net caching sitecore sitecore8


    【解决方案1】:

    是的 - Sitecore 这样做的方式是将用户详细信息添加到缓存键以进行渲染。这是存储在 html 缓存中,因此要清除它,您需要获取 html 缓存并清除所有包含用户名的条目。

    这个 sn-p 会这样做:

    // Need to clear the cache for the header and the user profile....
    var htmlCache = CacheManager.GetHtmlCache(Context.Site);
    
    // Remove all cache keys that contain the currently logged in user.
    var cacheKey = $"#login:True_#user:{Context.GetUserName()}";
    htmlCache.RemoveKeysContaining(cacheKey);
    

    这会清除当前登录用户的 html 缓存中的所有条目。如果您想为其他用户清除,只需更改Context.GetUserName() 以获取您要清除的特定用户。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多