Changes to TradeBlotter cache
This commit is contained in:
@@ -90,6 +90,7 @@ namespace TradeBlotter.Cache
|
|||||||
while(threadRun)
|
while(threadRun)
|
||||||
{
|
{
|
||||||
Thread.Sleep(quantumInterval);
|
Thread.Sleep(quantumInterval);
|
||||||
|
if(!threadRun)break;
|
||||||
quantums+=quantumInterval;
|
quantums+=quantumInterval;
|
||||||
if(quantums>cacheRefreshAfter)
|
if(quantums>cacheRefreshAfter)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ namespace TradeBlotter.Cache
|
|||||||
public class SymbolCache : IDisposable
|
public class SymbolCache : IDisposable
|
||||||
{
|
{
|
||||||
private List<String> symbolCache=new List<String>();
|
private List<String> symbolCache=new List<String>();
|
||||||
private Object thisLock=new Object();
|
private readonly Object thisLock=new Object();
|
||||||
|
private readonly Object fetchLock = new Object();
|
||||||
private Thread cacheMonitorThread=null;
|
private Thread cacheMonitorThread=null;
|
||||||
private volatile bool threadRun=true;
|
private volatile bool threadRun=true;
|
||||||
private int cacheRefreshAfter=60000; // Invalidate cache after
|
private int cacheRefreshAfter=60000; // Invalidate cache after
|
||||||
@@ -42,12 +43,15 @@ namespace TradeBlotter.Cache
|
|||||||
symbolCache=new List<string>();
|
symbolCache=new List<string>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
lock(thisLock)
|
lock(thisLock)
|
||||||
{
|
{
|
||||||
if(null==symbolCacheInstance || false==threadRun)return;
|
if(null==symbolCacheInstance || false==threadRun)return;
|
||||||
threadRun=false;
|
threadRun=false;
|
||||||
|
symbolCacheInstance=null;
|
||||||
|
}
|
||||||
if(null!=cacheMonitorThread)
|
if(null!=cacheMonitorThread)
|
||||||
{
|
{
|
||||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[SymbolCache:Dispose]Thread state is {0}. Joining main thread...",Utility.ThreadStateToString(cacheMonitorThread)));
|
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[SymbolCache:Dispose]Thread state is {0}. Joining main thread...",Utility.ThreadStateToString(cacheMonitorThread)));
|
||||||
@@ -55,18 +59,26 @@ namespace TradeBlotter.Cache
|
|||||||
cacheMonitorThread=null;
|
cacheMonitorThread=null;
|
||||||
MDTrace.WriteLine(LogLevel.DEBUG,"[SymbolCache:Dispose] End.");
|
MDTrace.WriteLine(LogLevel.DEBUG,"[SymbolCache:Dispose] End.");
|
||||||
}
|
}
|
||||||
symbolCacheInstance=null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> GetSymbols()
|
public List<String> GetSymbols()
|
||||||
{
|
{
|
||||||
lock(this)
|
lock(thisLock)
|
||||||
{
|
{
|
||||||
if(0==symbolCache.Count)symbolCache=PricingDA.GetSymbols();
|
if(symbolCache.Count>0)return new List<string>(symbolCache);
|
||||||
return symbolCache;
|
}
|
||||||
|
lock(fetchLock)
|
||||||
|
{
|
||||||
|
List<String> symbols = PricingDA.GetSymbols();
|
||||||
|
lock(thisLock)
|
||||||
|
{
|
||||||
|
if(symbolCache.Count>0)return new List<string>(symbolCache);
|
||||||
|
symbolCache=new List<String>(symbols);
|
||||||
|
return new List<string>(symbols);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ThreadProc()
|
private void ThreadProc()
|
||||||
{
|
{
|
||||||
int quantums=0;
|
int quantums=0;
|
||||||
@@ -74,14 +86,15 @@ namespace TradeBlotter.Cache
|
|||||||
while(threadRun)
|
while(threadRun)
|
||||||
{
|
{
|
||||||
Thread.Sleep(quantumInterval);
|
Thread.Sleep(quantumInterval);
|
||||||
|
if(!threadRun)break;
|
||||||
quantums+=quantumInterval;
|
quantums+=quantumInterval;
|
||||||
if(quantums>cacheRefreshAfter)
|
if(quantums>cacheRefreshAfter)
|
||||||
{
|
{
|
||||||
quantums=0;
|
quantums=0;
|
||||||
|
List<String> symbols = PricingDA.GetSymbols();
|
||||||
lock(thisLock)
|
lock(thisLock)
|
||||||
{
|
{
|
||||||
// symbolCache.Clear();
|
symbolCache=new List<string>(symbols);
|
||||||
symbolCache=PricingDA.GetSymbols();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user