The SPSite constructor (new SPSite(mySiteId)
) returns a cached entry, even though the site no longer exists. How can I prevent this?
SPSite constructor returns cached instance.
299 views Asked by kjv At
3
There are 3 answers
0
On
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.
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.