I am implementing am observable cache by referring DynamicTrader
I want to keep the max count of caches 1000. However the limitToSize() can limit the cache only.The actual count of objects was not affected by this method.
Kindly find my comments included in codes as below.
private IObservable<IChangeSet<UnaryTrackModel, long>> LoadAndMaintainCache()
{
return ObservableChangeSet.Create<UnaryTrackModel, long>(caches =>
{
var cacheCleaner = _trackCacheObservable.Subscribe(t =>
{
//I want to limit the cache count to 1000,in the not only cache but also memory
caches.AddOrUpdate(t);
});
//this line can limit the cache data.But it doesn't work on memory.
//I can find more than 1000 objects of UnaryTrackModel in memory snapshot.
//caches.LimitSizeTo(1000).Subscribe();
return new CompositeDisposable(cacheCleaner);
}, track => track.Id);
}
