public void CacheEviction(Object o, EventArgs args) {
Brunet.Collections.Cache.EvictionArgs eargs = (Brunet.Collections.Cache.EvictionArgs) args;
MemBlock key = (MemBlock) eargs.Key;
if(Dht.DhtLog.Enabled) {
ProtocolLog.Write(Dht.DhtLog, String.Format(
"Evicted out of cache {0}, entries in dht {1}, entries in cache {2}",
(new BigInteger(key)).ToString(16), Count, _data.Count));
}
if(eargs.Value != null && ((LinkedList<Entry>) eargs.Value).Count > 0) {
LinkedList<Entry> data = (LinkedList<Entry>) eargs.Value;
// AdrConverter doesn't support LinkedLists
Entry[] entries = new Entry[data.Count];
data.CopyTo(entries, 0);
Hashtable[] ht_entries = new Hashtable[entries.Length];
int index = 0;
foreach(Entry entry in entries) {
ht_entries[index++] = (Hashtable) entry;
}
string dir_path, filename;
string file_path = GeneratePath(key, out dir_path, out filename);
if(!Directory.Exists(dir_path)) {
Directory.CreateDirectory(dir_path);
}
using (FileStream fs = File.Open(file_path, FileMode.Create)) {
AdrConverter.Serialize(ht_entries, fs);
}
}
}