Created
August 13, 2014 16:52
-
-
Save cskeppstedt/d8b4b1ab550dc2c49b3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool TryGetTasksFromCache(int userId = -1, string stage, out List<UserTask> cachedTasks) | |
{ | |
cachedTasks = DataCache[GetCacheKey(userId, stage)] as List<UserTask>; | |
return (cachedTasks != null); | |
} | |
List<UserTask> GetTasks(int userId = -1, string stage, List<Severity> severities = null) | |
{ | |
List<UserTask> listOfUserTasks; | |
if (TryGetTasksFromCache(userId, stage, out listOfUserTasks)) | |
return listOfUserTasks; | |
listOfUserTasks = GetTasksNotFromCache(userId, stage, severities); | |
SetDataCache(userId, stage, listOfUserTasks); | |
return listOfUserTasks; | |
} | |
void ClearDataCache(int userId, string stage) | |
{ | |
DataCache.Remove(GetCacheKey(userId, stage)); | |
} | |
void SetDataCache(int userId, string stage, List<UserTask> tasks) | |
{ | |
// cache policy | |
var policy = new CacheItemPolicy | |
{ | |
AbsoluteExpiration = DateTimeOffset.UtcNow.AddSeconds(DATA_CACHE_NUMBER_OF_SECONDS) | |
}; | |
// storing data in cache. | |
DataCache.Set(GetCacheKey(userId, stage), tasks, policy); | |
} | |
string GetCacheKey(int userId, string stage) | |
{ | |
return "listOfBaseTasks" + userId + stage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment