public void Put(string key, T tag) { try { lock (_lock) { if (key == null) { return; } using (var db = new LiteDatabase(_dataBaseFile)) { _fileHashCollection = db.GetCollection <FileHashTableEntry <T> >(_databaseName); var results = _fileHashCollection.FindOne(x => x.Key.Equals(key)); if (results != null) { results.Tag = tag; results.DeleteDate = DateTime.UtcNow + TimeSpan.FromSeconds(_expirationTime); _fileHashCollection.Update(results); } else { var ob = new FileHashTableEntry <T> { Key = key, Tag = tag, DeleteDate = DateTime.UtcNow + TimeSpan.FromSeconds(_expirationTime) }; // binary-encoded format. Extends the JSON model to provide // additional data types, ordered fields and it's quite // efficient for encoding and decoding within different languages var mapper = new BsonMapper(); var doc = mapper.ToDocument(typeof(FileHashTableEntry <T>), ob); _fileHashCollection.Insert(ob); } } } } catch (Exception ex) { _logger.Error("LifeTimeStorage.Put() - " + ex.Message); } }
private static void LifeTimeStorage_FileHashTableRemoveEntry(string key, FileHashTableEntry <string> entry) { System.Console.WriteLine("I've just removed: " + key); }