public override bool OnStart() { CfTrace.InitializeTraceSource(new Instrumentation.CfTraceSource("Cf.CacheServer")); try { var connectionString = ConfigurationManager.ConnectionStrings["CfCloudStorage"].ConnectionString; CfCloudStorage = CloudStorageAccount.Parse(connectionString); //System.Diagnostics.Trace.WriteLine("cf.CacheServer Started: "+DateTime.UtcNow.ToString()); var startTime = DateTime.UtcNow; var stopwatch = new Stopwatch(); stopwatch.Start(); proc = WazMemcachedHelpers.StartMemcachedServer("Memcached", 640); proc.Exited += new EventHandler(MemcachedServer_Crashed); var index = PopuluteCfCacheIndex(); stopwatch.Stop(); //System.Diagnostics.Trace.WriteLine(string.Format("cf.CacheServer index [{0}], Ready after {1}ms", index.Count, stopwatch.ElapsedMilliseconds)); StartServiceHost(); //Listen for manual cache refreshes } catch (Exception ex) { CfTrace.Error(ex); } return(base.OnStart()); }
private List <CfCacheIndexEntry> PopuluteCfCacheIndex() { //MailMan.SendAppEvent(TraceCode.AppBuildCache, "Refreshing cache server index cache + lucene index", "*****@*****.**", Guid.Empty, "*****@*****.**", false); var client = WazMemcachedHelpers.CreateProtobufferClient("cf.CacheServer", "Memcached"); var index = new cf.DataAccess.Repositories.CFCacheIndexEntryRepository().GetAll().ToList(); client.FlushAll(); //-- do this after GetAll() to minimize the possibility of the cache being down... foreach (var entry in index) { AddIndexEntryToCache(entry, client); } //-- while we're here.. let's take care of lucene too RebuildLuceneIndex(); return(index); }