private static EntityContents GetEntityContents(SPWeb web, string containerTitle, Guid entityId) { SPList list; SPFolder folder; if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false) { return(null); } SPFile defaultEntityPart; if (SPDocumentStoreHelper.TryGetDocumentStoreDefaultEntityPart(list, folder, entityId, out defaultEntityPart) == false) { return(null); } EntityContents entityContents = SPDocumentStoreHelper.GetEntityContentsEntityPart(web, list, defaultEntityPart.ParentFolder); if (entityContents == null) { throw new NotImplementedException(); // TODO: Build it, update the hash yada yada. } return(entityContents); }
public override Entity GetEntity(string containerTitle, Guid entityId, string path) { //Get a new web in case we're executing in elevated permissions. using (var site = new SPSite(this.DocumentStoreUrl)) { using (var web = site.OpenWeb()) { var contentsHash = SPDocumentStoreHelper.GetEntityContentsHash(web, containerTitle, entityId); //If the contents hash is not set, fall back on just retrieving the entity. if (String.IsNullOrEmpty(contentsHash)) { return(base.GetEntity(containerTitle, entityId, path)); } //If we found it in the cache, return the entity value. var cachedValue = HttpRuntime.Cache[EntityContentsCachePrefix + "_" + entityId + "_" + contentsHash]; if (cachedValue is EntityContents) { var cachedEntityContents = cachedValue as EntityContents; //If it hasn't changed, return a clone of the entity. if (cachedEntityContents.Entity.ContentsETag == contentsHash) { return(DocumentStoreHelper.CloneObject(cachedEntityContents.Entity)); } } EntityContents entityContents = GetEntityContents(web, containerTitle, entityId); HttpRuntime.Cache.Add(EntityContentsCachePrefix + "_" + entityId + "_" + contentsHash, entityContents, null, Cache.NoAbsoluteExpiration, CacheSlidingExpiration, CacheItemPriority.Normal, null); return(DocumentStoreHelper.CloneObject(entityContents.Entity)); } } }