/// <summary> /// Updates any Cache Objects that are associated with this entity /// </summary> /// <param name="entityState">State of the entity.</param> /// <param name="dbContext">The database context.</param> public void UpdateCache(EntityState entityState, Rock.Data.DbContext dbContext) { // Make sure CampusCache.All is cached using the dbContext (to avoid deadlock if snapshot isolation is disabled) var campusId = this.GetCampusId(dbContext as RockContext); NamedLocationCache.FlushItem(this.Id); // CampusCache has a CampusLocation that could get stale when Location changes, so refresh the CampusCache for this location's Campus if (this.CampusId.HasValue) { CampusCache.UpdateCachedEntity(this.CampusId.Value, EntityState.Detached); } // and also refresh the CampusCache for any Campus that uses this location foreach (var campus in CampusCache.All(dbContext as RockContext).Where(c => c.LocationId == this.Id)) { CampusCache.UpdateCachedEntity(campus.Id, EntityState.Detached); } }