private static string CheckRequestCache(Database db, RequestID rid, string UserID, string url) { DateTime dt = TimeZone.CurrentTimeZone.ToUniversalTime(DateTime.Now); RequestCacheCollection col = new RequestCacheCollection(); IDBCollection icol = (IDBCollection)col; icol.SetConstraint((long)RequestCache.QueryValues.UserID, new DBConstraint(DBConstraint.QueryConstraints.Equal, UserID)); icol.SetConstraint((long)RequestCache.QueryValues.ValidUntil, new DBConstraint(DBConstraint.QueryConstraints.Greater, dt.ToOADate().ToString())); icol.SetConstraint((long)RequestCache.QueryValues.url, new DBConstraint(DBConstraint.QueryConstraints.Equal, url)); db.ReadRecord((IDBCollection)col); IDBCollectionContents ccol = (IDBCollectionContents)col; if (0 == ccol.Count()) { return(null); } IDBRecord rec = ccol.GetRecordInterface(0); RequestObject obj = (RequestObject)rec.GetDataObject(); Logger.ReportNotice("Using cached response, can make a new call after " + obj.ValidUntil.ToString()); return(Compression.Decompress(obj.Response)); }
private static void WriteRequestCache(Database db, RequestID rid, string UserID, string url, string s) { RequestCacheCollection col = new RequestCacheCollection(rid, UserID, url, s); IDBCollectionContents ccol = (IDBCollectionContents)col; for (int i = 0; i < ccol.Count(); ++i) { // this loop should normally have only 1 iteration Logger.ReportNotice("Response Cached."); db.InsertRecord(ccol.GetRecordInterface(i)); } }