query cache and/or database

  • 62 Views
  • Last Post 27 March 2017
joshyates1980 posted this 27 March 2017

Is this code snippet querying the cache?  I stepped through the code and it appears to hit the database.  Can I view the cache in Google Chrome console to verify the data is cache?

public MembershipUser Get(Guid id)
{
    var cacheKey = string.Concat(CacheKeys.Member.StartsWith, "get-", id);
    return _cacheService.CachePerRequest(cacheKey, () =>
    {
        return _context.MembershipUser
                              .Include(x => x.Roles)
                              .FirstOrDefault(x => x.Id == id);
    });
}

joshyates1980 posted this 27 March 2017

This appears to be a good example of how you get/set from cache:

public Settings GetSettings(bool useCache = true) { if (useCache) { var cachedSettings = _cacheService.Get<Settings>(CacheKeys.Settings.Main); if (cachedSettings == null) { cachedSettings = GetSettingsLocal(false); _cacheService.Set(CacheKeys.Settings.Main, cachedSettings, CacheTimes.OneDay); } return cachedSettings; } return GetSettingsLocal(true); }

Close