public async Task<IHttpActionResult> Get() { var cache = RedisCache.Connection.GetDatabase(); var repo = new RedisRepository(cache); string owner = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value; var items = await repo.GetPhotosForUserAsync(owner); //Do this so we can get the count List<IPhotoModel> typedItems = new List<IPhotoModel>(items); if(typedItems.Count == 0) { //Nothing in cache... head off to storage. var storageRepo = new StorageRepository(SettingsHelper.LocalStorageConnectionString); var photos = await storageRepo.GetPhotosFromTableAsync( DAL.Azure.StorageConfig.TableName, owner); foreach (var photo in photos) { //TODO: Find a MUCH better algorithm than // iterating every item and calling // Redis 3 times in a row for each // item. This is PAINFUL. await repo.AddPhotoToCachesAsync(photo); } items = photos; } return Ok(items); }
internal static async Task SaveToRedisAsync(PhotoModel p, TextWriter log) { //Use repository to add to all caches IDatabase cache = RedisCache.Connection.GetDatabase(); RedisRepository repo = new RedisRepository(cache); await repo.AddPhotoToCachesAsync(p); }
public async Task <IHttpActionResult> Get() { var cache = RedisCache.Connection.GetDatabase(); var repo = new RedisRepository(cache); string owner = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value; var items = await repo.GetPhotosForUserAsync(owner); //Do this so we can get the count List <IPhotoModel> typedItems = new List <IPhotoModel>(items); if (typedItems.Count == 0) { //Nothing in cache... head off to storage. var storageRepo = new StorageRepository(SettingsHelper.LocalStorageConnectionString); var photos = await storageRepo.GetPhotosFromTableAsync(DAL.Azure.StorageConfig.TableName, owner); foreach (var photo in photos) { //TODO: Find a MUCH better algorithm than // iterating every item and calling // Redis 3 times in a row for each // item. This is PAINFUL. await repo.AddPhotoToCachesAsync(photo); } items = photos; } return(Ok(items)); }
public async Task <IHttpActionResult> GetPhotoModel(string id) { var cache = RedisCache.Connection.GetDatabase(); var repo = new RedisRepository(cache); //Get a single item from the cache based on its ID var photo = await repo.GetPhotoByIDAsync(id); if (null == photo) { //Not in the cache. Try to retrieve based on // current user. This won't work if it's another user's photo. if (User.Identity.IsAuthenticated) { string connectionString = SettingsHelper.LocalStorageConnectionString; string owner = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value; var storageRepo = new StorageRepository(connectionString); photo = await storageRepo.GetPhotoFromTableAsync(DAL.Azure.StorageConfig.PhotosBlobContainerName, owner, id); if (null == photo) { //Not found in cache or storage. } else { //Update the cache using the cache aside pattern. await repo.AddPhotoToCachesAsync(photo); } } } if (null != photo) { return(Ok(photo)); } else { return(NotFound()); } }
public async Task<IHttpActionResult> GetPhotoModel(string id) { var cache = RedisCache.Connection.GetDatabase(); var repo = new RedisRepository(cache); //Get a single item from the cache based on its ID var photo = await repo.GetPhotoByIDAsync(id); if(null == photo) { //Not in the cache. Try to retrieve based on // current user. This won't work if it's another user's photo. if(User.Identity.IsAuthenticated) { string connectionString = SettingsHelper.LocalStorageConnectionString; string owner = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value; var storageRepo = new StorageRepository(connectionString); photo = await storageRepo.GetPhotoFromTableAsync(DAL.Azure.StorageConfig.PhotosBlobContainerName, owner, id); if (null == photo) { //Not found in cache or storage. } else { //Update the cache using the cache aside pattern. await repo.AddPhotoToCachesAsync(photo); } } } if(null != photo) { return Ok(photo); } else { return NotFound(); } }