public void SaveData() { if (!File.Exists(CacheFilePath)) { Log("No Cache file: " + CacheFilePath); return; } string[] cacheStrings = File.ReadAllText(CacheFilePath, ENCODING).Split(DELIM_OPR); HashSet <string> dataNames = new HashSet <string>(); foreach (string cacheString in cacheStrings) { if (string.IsNullOrEmpty(cacheString)) { continue; } DBCache cache = DBCache.LoadFromString(cacheString); dataNames.Add(cache.dataName); } foreach (string dataName in dataNames) { SaveData(dataName); } File.WriteAllText(CacheFilePath, string.Empty, ENCODING); cacheCount = 0; }
protected void LoadCache() { if (!File.Exists(CacheFilePath)) { return; } string[] cacheStrings = File.ReadAllText(CacheFilePath, ENCODING).Split(DELIM_OPR); foreach (string cacheString in cacheStrings) { if (string.IsNullOrEmpty(cacheString)) { continue; } DBCache cache = DBCache.LoadFromString(cacheString); DBData data = LoadData(cache.dataName); switch (cache.operation) { case Operation.Add: data.Add(cache.key, cache.value); break; case Operation.Set: data.Set(cache.key, cache.value); break; case Operation.Del: data.Del(cache.key); break; } SaveData(cache.dataName); } File.WriteAllText(CacheFilePath, string.Empty, ENCODING); cacheCount = 0; }
public bool Set(string dataName, object key, object value) { DBData data = LoadData(dataName); if (!data.Set(key, value)) { LogWarning("Set failed: " + dataName + "[" + key + "]"); return(false); } DBCache cache = new DBCache(dataName, Operation.Set, key.ToString(), value.ToString()); SaveCache(cache.ToString()); return(true); }
public bool Del(string dataName, object key) { DBData data = LoadData(dataName); if (!data.Del(key)) { LogWarning("Del failed: " + dataName + "[" + key + "]"); return(false); } DBCache cache = new DBCache(dataName, Operation.Del, key.ToString(), string.Empty); SaveCache(cache.ToString()); return(true); }
public bool Set(string dataName, string key, object value) { string serializedValue = JsonConvert.SerializeObject(value); DBData data = LoadData(dataName); if (!data.Set(key, serializedValue)) { LogWarning("Set failed: " + dataName + "[" + key + "]"); return(false); } DBCache cache = new DBCache(dataName, DBCache.Operation.Set, key, serializedValue); SaveCache(cache.ToString()); return(true); }