query cache and/or database

  • Last Post 4 weeks ago
joshyates1980 posted this 4 weeks ago

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 4 weeks ago

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); }