// Load user from database or cache public User LoadUser(int id) { // Get cache key string cacheKey = "User" + id.ToString(); // Try to load user from cache User user = MemoryCache.Default.Get(cacheKey) as User; if (user != null) return user; // Now lock with cacheKey // Read user from database user = LoadUserFromDatabase(id); // Save user to cache MemoryCache.Default.Set(cacheKey, user, <some cache time>); return user; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)