示例#1
0
 protected override async Task InnerSet(string key, string value)
 {
     if (_useCache)
     {
         await _cache.SetString(key, value);
     }
     if (value == null)
     {
         using (var db = new LiteDatabase(_dbFilePath))
         {
             var collection = db.GetCollection <BsonDocument>(_collectionName);
             collection.Delete(key);
         }
     }
     else
     {
         using (var db = new LiteDatabase(_dbFilePath))
         {
             var collection = db.GetCollection <BsonDocument>(_collectionName);
             collection.Upsert(
                 new BsonDocument
             {
                 ["_id"]   = key,
                 ["Value"] = value
             }
                 );
         }
     }
 }
 protected override async Task InnerSet(string key, string value)
 {
     if (_useCache)
     {
         await _cache.SetString(key, value);
     }
     if (value == null)
     {
         await _collection.DeleteOneAsync(d => d["key"] == key);
     }
     else
     {
         await _collection.UpsertAsync(
             d => d["key"] == key,
             new BsonDocument
         {
             ["key"]   = key,
             ["Value"] = value
         }
             );
     }
 }