Skip to content

Commit

Permalink
Check transient errors (RedisConnectionException) #4
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabricio Catae committed Feb 22, 2017
1 parent e6bb777 commit b10a4fc
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/Arda.Permissions/Repositories/PermissionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public PermissionRepository(PermissionsContext context, IDistributedCache cache)
_context = context;
_cache = cache;
}

public bool SetUserPermissionsAndCode(string uniqueName, string code)
{
var userPermissions = (from u in _context.Users
Expand Down Expand Up @@ -85,18 +85,25 @@ public bool UpdateUserPermissions(string uniqueName, PermissionsViewModel newUse
_context.SaveChanges();

//Update the cache
CacheViewModel propertiesToCache;
CacheViewModel propertiesToCache = new CacheViewModel();
byte[] arrPropertiesSerializedCached = null;

try
{
//User is on cache:
var propertiesSerializedCached = Util.GetString(_cache.Get(uniqueName));
propertiesToCache = new CacheViewModel(propertiesSerializedCached);
// may raise exception
arrPropertiesSerializedCached = _cache.Get(uniqueName);

// if data is not cached
if(arrPropertiesSerializedCached != null)
{
string propertiesSerializedCached = Util.GetString(arrPropertiesSerializedCached);
propertiesToCache = new CacheViewModel(propertiesSerializedCached);
}
}
catch
catch (StackExchange.Redis.RedisConnectionException)
{
//User is not on cache:
propertiesToCache = new CacheViewModel();
}
// Ignore transient network errors
}

var userPermissions = (from up in _context.UsersPermissions
join r in _context.Resources on up.ResourceID equals r.ResourceID
Expand Down

0 comments on commit b10a4fc

Please sign in to comment.