public static T Get(string key, Mutator mutator = null, bool bypassCache = false) { ValidateState(EActionType.Read); if (key == null) { return(null); } if (Info <T> .Settings.KeyMemberName == null) { if (!Info <T> .Settings.Silent) { Current.Log.Warn <T>("Invalid operation; key not set"); } throw new MissingPrimaryKeyException("Key not set for " + typeof(T).FullName); } var fullKey = mutator?.KeyPrefix + key; if (!Info <T> .Configuration.UseCaching || bypassCache) { return(FetchModel(key, mutator)); } return(CacheFactory.FetchModel <T>(fullKey) ?? FetchModel(key, mutator)); }
public static FilterPackage GetPersonFilterPackage(string locator) { if (locator == null) { locator = NoUserLocator; } return(CacheFactory.FetchModel(InternalGetPersonFilterPackage, locator)); }
internal static Dictionary <string, T> FetchSet(IEnumerable <string> keys, bool bypassCache = false, Mutator mutator = null) { //This function mixes cached models with partial queries to the adapter. var fetchKeys = keys.ToList(); // First we create a map to accomodate all the requested records. var fetchMap = fetchKeys.ToDictionary(i => i, i => (T)null); //Then we proceed to probe the cache for individual model copies if the user didn't decided to ignore cache. var cacheKeyPrefix = mutator?.KeyPrefix; if (!bypassCache) { foreach (var key in fetchKeys) { fetchMap[key] = CacheFactory.FetchModel <T>(cacheKeyPrefix + key); } } //At this point we may have a map that's only partially populated. Let's then identify the missing models. var missedKeys = fetchMap.Where(i => i.Value == null).Select(i => i.Key).ToList(); //Do a hard query on the missing keys. var cachedSet = Info <T> .Settings.Adapter.Get(missedKeys, mutator).ToList(); // Post-fetch hook foreach (var model in cachedSet) { model.AfterGet(); } // Now we fill the map with the missing models that we sucessfully fetched. foreach (var model in cachedSet.Where(model => model != null)) { var key = cacheKeyPrefix + model.GetDataKey(); fetchMap[key] = model; // And we take the time to populate the cache with the model. CacheFactory.StoreModel(key, model); } //Let's return the map and give the developer the chance to handle unbound keys. return(fetchMap); }