SPSite 构造函数返回缓存的实例。
即使站点不再存在,SPSite 构造函数 (new SPSite(mySiteId)
) 也会返回缓存的条目。我怎样才能防止这种情况发生?
The SPSite constructor (new SPSite(mySiteId)
) returns a cached entry, even though the site no longer exists. How can I prevent this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们遇到了同样的问题,但尚未找到解决方案。我们尝试通过调用静态 SPSite.Exists(..) 方法来检查 SPSite 是否存在。对于不再存在的站点,该方法也返回 true。
但我们找到了一些解决方法。我们尝试通过调用SPSite 的Usage 属性来引发FileNotFoundException。当异常出现时,我们知道该站点不再存在。
捕获异常后,您可以再次调用 SPSite.Exists() 方法,该方法现在将返回 false。
We had the same problem and haven't found a solution for it yet. We tried to check whether a SPSite exists or not by calling the static SPSite.Exists(..) method. The method returned true also for sites that didn't exist any more.
But we have found a little workaround. We try to provoke a FileNotFoundException by calling the SPSite's Usage property. When the exception arise we know that the site doesn't exist any more.
After catching the exception you can call again the SPSite.Exists() method which will now return false.
虽然我不知道 Sharepoint 详细信息,但我可以告诉您调用
new
将永远返回缓存的对象。尽管内部可能指向缓存的对象,但它将始终是新分配的对象。While I do not know the Sharepoint details, I can tell you calling
new
will NEVER return a cached object. It will ALWAYS be a newly allocated object, although the internals may point to cached objects.也许有点晚了,但因为我也遇到了同样的问题。
您可以在 SPSite 类上调用 satic 方法 InvalidateCacheEntry(Uri uri, Guid siteId)。通过传递一个空的 guid 和您正在使用的 SPSite 的 uri,您应该能够清除缓存并获取当前值。
请注意,这似乎也是 SPSite.Exists 对于刚刚删除的网站返回“true”问题的原因。通过使用 InvalidateCacheEntry 方法,我能够检测到站点的正确状态(已删除或存在)。我不知道这种解决方法的性能成本是多少,但如果您将来遇到类似的问题,请考虑它。
A little late maybee, but since I had this same problem.
You can call the satic method InvalidateCacheEntry(Uri uri, Guid siteId) on the SPSite class. By passing an empty guid and the uri of the SPSite you are using, you should be able to clear the cache and get the current values.
Notice that this seems to be also the cause of the issue of SPSite.Exists returning "true" for just deleted sites. By using the InvalidateCacheEntry method, I was able to detect the correct state of the site (deleted or existent). I don't know what is the performance cost of this workaround, but please consider it if you have a similar problem in the future.