public static bool AddEntry(Entry entry) { bool result; if (string.IsNullOrEmpty(entry.Content)) { return(false); } SqlServerIo sql = SqlServerIo.Create(); if (!sql.Ready) { return(false); } //naa entry.FixForMultipleLineFeeds(); result = sql.Execute(false, NEW_ENTRY_SQL, entry.Baslik, entry.Suser, entry.Date.ToString(), entry.Content); if (result) { if (!sql.Read()) { result = false; } else { entry.SetId(sql.GetValueOfColumn <int>("BaslikId")); CacheManager.InvalidateCacheSet(KeysetId.Baslik(entry.BaslikID)); var indexKeyid = KeysetId.Index(entry.Baslik[0]); CacheManager.InvalidateCacheSet(indexKeyid); if (sql.GetValueOfColumn <int>("IsNewBaslikInsert") == 1) { //invalidate also todays section keyset a.k.a Taze CacheManager.InvalidateCacheSet(KeysetId.Todays()); } } } SqlServerIo.Release(sql); return(result); }
public static ViewQueryResult FetchEntriesOfBaslik(string baslik, int baslikId, int pageNumber) { SqlServerIo sql; string query; ViewQueryResult resultSet; query = BuildEntryFetchSQL(baslik, baslikId, pageNumber); if (!CacheManager.TryGetCachedQueryResult <ViewQueryResult>(query, out resultSet)) { sql = SqlServerIo.Create(); if (!sql.Execute(false, query)) { SqlServerIo.Release(sql); return(new ViewQueryResult()); } resultSet = new ViewQueryResult(); while (sql.Read()) { if (resultSet.TotalRecordCount == 0) { resultSet.TotalRecordCount = sql.GetValueOfColumn <int>("TotalRecord"); resultSet.BaslikId = sql.GetValueOfColumn <int>("Id"); } Entry e = new Entry( sql.GetValueOfColumn <string>("Baslik"), sql.GetValueOfColumn <string>("Suser"), sql.GetValueOfColumn <DateTime>("SubmitDate").ToString(), sql.GetValueOfColumn <string>("Entry")); resultSet.Entries.Add(e); resultSet.PhysicalRecordCount++; } SqlServerIo.Release(sql); //Dont cache for empty recordset for baslik if (!resultSet.HasEntry) { return(resultSet); } resultSet.LogicalRecordCount = resultSet.PhysicalRecordCount; CacheManager.CacheObject(KeysetId.Baslik(resultSet.BaslikId), true, query, resultSet); BaslikBasicInfo bbi = new BaslikBasicInfo() { TotalEntries = resultSet.TotalRecordCount }; CacheManager.CacheObject("BBI_" + resultSet.BaslikId.ToString(), bbi, TimeSpan.FromMinutes(10)); //if this request initial fetch using the baslik string. //rebuild sql with baslikid and cache the result with its hashkey if (baslikId == 0) { query = BuildEntryFetchSQL(null, resultSet.BaslikId, pageNumber); CacheManager.CacheObject(KeysetId.Baslik(resultSet.BaslikId), true, query, resultSet); } } return(resultSet); }