protected static void getVoid(DataBase dataBase, Where <T> where) { var stopwatch = Stopwatch.StartNew(); try { using (var scope = new NrdoScope(dataBase)) { scope.ExecuteSql(where.SQLStatement, where.SetOnCmd, where.CommandType); } } finally { stopwatch.Stop(); NrdoStats.UpdateGlobalStats(stats => stats.WithModification(stopwatch.Elapsed)); log(stopwatch, "db-hit-void", where); } }
protected static T getSingle(Where <T> where) { var stopwatch = Stopwatch.StartNew(); bool succeeded = false; if (where.Cache == null) { try { var result = doGetSingle(DataBase, where); succeeded = true; return(result); } finally { stopwatch.Stop(); NrdoStats.UpdateGlobalStats(stats => succeeded ? stats.WithCacheSkip(stopwatch.Elapsed) : stats.WithFailure(stopwatch.Elapsed)); } } var cache = (IDBSingleObjectCache <T>) where.Cache; long modCountHash; lock (Nrdo.LockObj) { // Try the cache. If it succeeds, return the result. If it fails, save the cache's ModificationCountHash T cacheResult; if (cache.TryGetValue(where, out cacheResult)) { where.Cache.HitInfo.updateStats(stats => stats.WithCacheHit(), stats => stats.WithSingleCacheHit()); log("cache-hit-single", where); stopwatch.Stop(); return(cacheResult == null ? null : cacheResult.FieldwiseClone()); } modCountHash = cache.ModificationCountHash; } // Hit the DB try { var result = doGetSingle(DataBase, where); succeeded = true; lock (Nrdo.LockObj) { // Check the cache's ModificationCountHash. If it equals the saved value, store the value. Otherwise don't. if (cache.ModificationCountHash == modCountHash) { cache.StoreValue(where, result == null ? null : result.FieldwiseClone()); } // Return the result. return(result); } } finally { lock (Nrdo.LockObj) { stopwatch.Stop(); if (!succeeded) { where.Cache.HitInfo.updateStats(stats => stats.WithFailure(stopwatch.Elapsed), stats => stats.WithFailure(stopwatch.Elapsed)); } else { where.Cache.HitInfo.updateStats(stats => stats.WithCacheMiss(stopwatch.Elapsed), stats => stats.WithSingleCacheNonHit(stopwatch.Elapsed, where.Cache.IsOverflowing)); } } } }
protected internal static List <T> getMulti <TWhere>(TWhere where) where TWhere : Where <T> { var stopwatch = Stopwatch.StartNew(); bool succeeded = false; if (where.Cache == null) { try { var result = doGetMulti(DataBase, where); succeeded = true; return(result); } finally { stopwatch.Stop(); NrdoStats.UpdateGlobalStats(stats => succeeded ? stats.WithCacheSkip(stopwatch.Elapsed) : stats.WithFailure(stopwatch.Elapsed)); } } var cache = (IDBMultiObjectCache <T>) where.Cache; long modCountHash; lock (Nrdo.LockObj) { // Try the cache. If it succeeds, return the result. If it fails, save the cache's ModificationCountHash List <T> cacheResult; if (cache.TryGetValue(where, out cacheResult)) { where.Cache.HitInfo.updateStats(stats => stats.WithCacheHit(), stats => stats.WithListCacheHit(cacheResult.Count)); log("cache-hit-multi", where); stopwatch.Stop(); return((from t in cacheResult select t.FieldwiseClone()).ToList()); } modCountHash = cache.ModificationCountHash; } // Hit the DB var skipped = false; int resultCount = 0; try { var result = doGetMulti(DataBase, where); succeeded = true; resultCount = result.Count; lock (Nrdo.LockObj) { // Check the cache's ModificationCountHash. If it equals the saved value, store the value. Otherwise don't. if (cache.ModificationCountHash == modCountHash) { if (cache.Capacity > 0 || result.Count <= cache.ItemCapacity) { cache.StoreValue(where, (from t in result select t.FieldwiseClone()).ToList()); } else { skipped = true; } } // Return the result. return(result); } } finally { lock (Nrdo.LockObj) { stopwatch.Stop(); if (!succeeded) { where.Cache.HitInfo.updateStats(stats => stats.WithFailure(stopwatch.Elapsed), stats => stats.WithFailure(stopwatch.Elapsed)); } else if (skipped) { where.Cache.HitInfo.updateStats(stats => stats.WithCacheSkip(stopwatch.Elapsed), stats => stats.WithListCacheSkip(resultCount, stopwatch.Elapsed)); } else { where.Cache.HitInfo.updateStats(stats => stats.WithCacheMiss(stopwatch.Elapsed), stats => stats.WithListCacheMiss(resultCount, stopwatch.Elapsed, where.Cache.IsOverflowing)); } } } }