Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public IQueryable<VictoryList> GetVictoryList()
- {
- string cacheKey = HttpContext.Current.User.Identity.Name + "victoryCacheKey";
- IQueryable<VictoryList> cachednews = (IQueryable<VictoryList>)HttpContext.Current.Cache.Get(cacheKey);
- if (cachednews == null)
- {
- var results = from v in _datacontext.ViewVictoryLists
- orderby _datacontext.GetNewId()
- select new VictoryList
- {
- MemberID = v.MemberID,
- Username = v.Aspnetusername,
- Location = v.Location,
- DaimokuGoal = v.DaimokuGoal,
- PreviewImageID = v.PreviewImageID,
- TotalDaimoku = v.TotalDaimoku,
- TotalDeterminations = v.TotalDeterminations,
- DeterminationID = v.DeterminationID,
- DeterminationName = v.DeterminationName
- };
- SqlCacheDependency dependency =
- new SqlCacheDependency(_datacontext.GetCommand(results) as SqlCommand);
- HttpContext.Current.Cache.Add(cacheKey, results, dependency, DateTime.MaxValue,
- TimeSpan.Zero, CacheItemPriority.Normal, null);
- return results.ToList().AsQueryable();
- }
- return cachednews;
- }
- public IQueryable<VictoryList> GetVictoryList() {
- // ...
- if (cachednews == null)
- {
- var results = from // ...
- results = results.ToList().AsQueryable(); // force query execution
- SqlCacheDependency dependency = // ...;
- HttpContext.Current.Cache.Add(cacheKey,
- results, // now just the result are stored
- dependency,
- DateTime.MaxValue,
- TimeSpan.Zero,
- CacheItemPriority.Normal,
- null);
- return results;
- }
- return cachednews;
- }
Add Comment
Please, Sign In to add comment