private void CheckCache(DateTime now) { //Check to see if the cache needs updating if (Timestamp.Subtract(now).TotalHours > Source.CacheLife) { //Update the cache: //Make a dispatcher to get the new count Records.Dispatcher dispatcher = new Records.Dispatcher(Source); Count = dispatcher.FetchTestRecordCount(tik); //Now update the cache Timestamp = Factory.UpdateCountCache(RCCID, Count); } }
public override RecordCountCache FetchCountCache(RecordSource source, int tik) { SQLiteCommand command = new SQLiteCommand("SELECT RCCID, TIK, Count, TimeStamp, DateTime() FROM RecordCountCache WHERE TIK=@tik AND RSID=@rsid", connection); command.Parameters.AddWithValue("@tik", tik); command.Parameters.AddWithValue("rsid", source.RSID); SQLiteDataReader reader = command.ExecuteReader(); if (reader.HasRows) { reader.Read(); return(new RecordCountCache(reader.GetInt32(0), reader.GetInt32(1), source, reader.GetInt32(2), Convert.ToDateTime(reader.GetString(3)), Convert.ToDateTime(reader.GetString(4)))); } else { //Need to create new count cache //Get the count from the source Records.Dispatcher dispatcher = new Records.Dispatcher(source); int count = dispatcher.FetchTestRecordCount(tik); //Insert and get the last ID so that it can be selected SQLiteCommand insertCommand = new SQLiteCommand("INSERT INTO RecordCountCache (RSID, TIK, Count, Timestamp) VALUES (@rsid, @tik, @count, DateTime())", connection); insertCommand.Parameters.AddWithValue("@rsid", source.RSID); insertCommand.Parameters.AddWithValue("@tik", tik); insertCommand.Parameters.AddWithValue("@count", count); insertCommand.ExecuteNonQuery(); //Created, now fetch by recursion return(FetchCountCache(source, tik)); } throw new NotImplementedException(); }