public List <GradeDto> GetGrades() { Func <List <GradeDto> > func = () => GetGradesInternal(); var dtos = CacheServiceHelper.Get <List <GradeDto> >("GetGrades", func); return(dtos); }
public GradeDetailDto GetSubTopicsByGradeIdUserName(int gradeId, string UserName) { Func <GradeDetailDto> func = () => GetSubTopicsByGradeIdUserNameInteral(gradeId, UserName); var cacheKey = String.Format("GetSubTopicsByGradeId_{0}", gradeId); var dtos = CacheServiceHelper.Get <GradeDetailDto>(cacheKey, func); return(dtos); }
private void Initialize() { if (isInitialized == false) { provider = CacheServiceHelper.GetRedisCacheServiceProvider(); isInitialized = true; } }
static void Main(string[] args) { List <UserAddressCacheModel> addresses = new List <UserAddressCacheModel>(); for (int i = 0; i < 100; i++) { //id - user id UserAddressCacheModel address = new UserAddressCacheModel { Id = i, Name = i + " street", Number = i }; addresses.Add(address); } int userId = 1; CacheWorker cacheWorker = new CacheWorker(userId, CacheServiceHelper.GetRedisCacheServiceProvider()); cacheWorker.SaveObjects(addresses); var address1 = cacheWorker.GetObjectById <UserAddressCacheModel>(11); Console.WriteLine("{0} {1} {2}", address1.Id, address1.Name, address1.Number); //Lock operation described by model in cache -> creates a cache entry that expires with time set in the model cacheWorker.LockResourceInCacheWithExpiration <ValidateDatabaseLockModel>(); bool doesLockModelExists = cacheWorker.DoesKeyExist <ValidateDatabaseLockModel>(); Console.WriteLine("Lock key exists : ? {0} ", doesLockModelExists); int sixtyOneSecondsInMilliseconds = 61 * 1000; Thread.Sleep(sixtyOneSecondsInMilliseconds); doesLockModelExists = cacheWorker.DoesKeyExist <ValidateDatabaseLockModel>(); Console.WriteLine("Lock key exists : ? {0} ", doesLockModelExists); Action lockResource = cacheWorker.LockResourceInCacheWithExpirationAction <DefaultRolePermissionsLockModel>(); lockResource(); cacheWorker.UnLockResourceInCacheWithExpiration <DefaultRolePermissionsLockModel>(); }