void WriteBuffer(bool force) { if (buffer.Count == 0) { return; } if (!force && buffer.Count < 4096) { return; } BlockDBFile.WriteEntries(stream, buffer); buffer.Count = 0; }
/// <summary> Flushes the entries from the in-memory cache to disc. </summary> /// <remarks> You must lock using Locker.AccquireWrite() **before** entering this method. </remarks> public void FlushCache() { if (Cache.Head == null) { return; } BlockDBFile format = ValidateBackingFile(); using (Stream s = OpenWrite()) { // This truncates the lower 4 bits off - so e.g. if a power off occurred // and 21 bytes were in the file, this sets the position to byte 16 s.Position = s.Length & ~0x0F; format.WriteEntries(s, Cache); Cache.Clear(); } }
public void WriteEntries() { using (IDisposable writeLock = locker.AccquireWriteLock()) { if (Cache.Count == 0) { return; } ValidateBackingFile(); using (Stream s = File.OpenWrite(FilePath)) { // This truncates the lower 4 bits off - so e.g. if a power off occurred // and 21 bytes were in the file, this sets the position to byte 16 s.Position = s.Length & ~0x0F; BlockDBFile.WriteEntries(s, Cache); lock (CacheLock) Cache = new FastList <BlockDBEntry>(); } } }