Question regarding objects and cache

N

NWx

Hi,

I discovered a strange (?!?!) issue related objects saved to cache.

Let's explain my situation.
I have a webform for user registration. Users enter username, password and
other info
Username must be unique, obviously, and this is enforced at database level,
with a unique index on username field.
I use a BO object to save / load data from database. This BO uses a DataRow
and SQLBuilder to save data to database.
The BO is declared as a private variable of my WebControl who manages
registration

I encountered the following situation:
1. At first load of the page (not IsPostback), I create the BO, initialize
it for new record (this adds an empty row to DataRow) and save it to cache.
2. After Postback, I reload load object from cache (all fields are empty, of
course)
3. In cmdSave_click, if validation is OK (no validation for unique username
though, since this is enforced by BE), try to save. If username is not
unique, save will fail and will return an error message.
I show the errormsg on the webpage, and let user to change data to save
again. Now BO's fields contains data entered by user who caused the save to
fail. I do not update cache with my BO.
After cmdSave_click finish, another roundtrip to client and back occurs.
User enter another data and click Save again.
Page_load is executed again, where I restore BO from cache (since it is
postback).
But here is the strange thing: the BO doesn't have fields empty (because,
remember, I saved it to cache when page was loaded first time, and BO was
empty at that time), but instead it contains values I set to it before
failed save (so previous postback !!!). But after failed save, I didn't
updated the object from cache with values entered by user!

So, why this was happening? Does ASP.NET knows how to automatically keep
sync between a member of the class and the cache (back and forth) when the
page is loaded again (postback)?
In this case, probably, I shouldn't restore BO from cache when postback?

Can anyone explain this?

Any comment will be appreciated!
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top