Caching problems

T

Tomasz

Hello,
i have following lines in my Page_Load:

Response.Expires = -1;
Response.AppendHeader("Pragma", "no-cache");
Response.Cache.SetNoStore();
Response.Cache.SetCacheability(HttpCacheability.NoCache);

I'm running this page additionally with dummy parameter:

Response.Redirect("Page.aspx" + "?x=" + Guid.NewGuid());

But still the page is cashed and my code is not rereading DB until i
press F5 in my browser (IE 7)!!!

Any tips ... ? Could it be a problem with browser ?
 
G

Guest

Tomasz,
When you say "my code is not reading the db until I press F5", you have
another issue here besides caching. The code in the page should always run,
whether you have attempted to tell receiving browser whether to cache the
page or not.

Perhaps you would like to post a "short but complete" code sample showing
how your code makes the database call?
Peter
 
T

Tomasz

Peter said:
Tomasz,
When you say "my code is not reading the db until I press F5", you have
another issue here besides caching. The code in the page should always run,
whether you have attempted to tell receiving browser whether to cache the
page or not.

Perhaps you would like to post a "short but complete" code sample showing
how your code makes the database call?

Hello,

This is my Page_Load function:

private void Page_Load(object sender, System.EventArgs e)
{
Response.Expires = -1;
Response.AppendHeader("Pragma", "no-cache");
Response.Cache.SetNoStore();
Response.Cache.SetCacheability(HttpCacheability.NoCache);

//Fill in Werker Liste
if ((!Page.IsPostBack) || (Request.QueryString["reload"] == "yes"))
{
LoadWorkers("");
}

//Fill in Abteilungen List
if (!Page.IsPostBack)
{
LoadDivisions();
}
}
I tried to remove Page.IsPostBack condition, but this is not working
too.

What is really important is LoadWorkers function:

private void LoadWorkers(string strDivision)
{
WerkerListe.Items.Clear();
DataSet DSWerker = new DataSet();
string WQuery = "SELECT * FROM Werker";
if (strDivision != "")
{
int AbteilungID = Int32.Parse(strDivision);
WQuery = WQuery + " WHERE AbteilungID=" + AbteilungID;
}

WQuery = WQuery + " ORDER BY Werkernachname ASC";

DSWerker = ADBEngine.GetDBData(WQuery, "Werker");
if ((DSWerker.Tables.Count > 0) & (DSWerker.Tables[0].Rows.Count >
0))
{
for (int i = 0; i < DSWerker.Tables[0].Rows.Count; i++)
{

object obj = DSWerker.Tables[0].Rows.ItemArray[1];
string werNach = (string)obj;
obj = DSWerker.Tables[0].Rows.ItemArray[2];
string werVor = (string)obj;
WerkerListe.Items.Add(werNach + " " + werVor);
obj = DSWerker.Tables[0].Rows.ItemArray[0];
int WID = (int)obj;
WerkerListe.Items[WerkerListe.Items.Count - 1].Value =
WID.ToString();
}
WerkerListe.SelectedIndex = 0;
}
}

ADBEngine is my class written only for this project to make reading
data from DB easier and more simple. This class is in moment maximally
simplified, and it is initialized in my webform class as follows:
protected AusbildungenEngine ADBEngine = new AusbildungenEngine();
constructor opens a database connection

What is really funny - i have on my page Label, which i use to debug
this code. So i put in LoadWorkers method few lines which are changing
text of this label to see if these lines are executed. So,
theoretically they where, but if i wanted to view f.e. current count of
rows of the table in DB then i got incorrect (old) count, so it looked
like it would be read from cache or something.

i hope i explained this enough clearly ;-)

Thanks in advance!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top