 |
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

October 15th, 2007, 09:29 AM
|
Friend of Wrox
|
|
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
run some function when cache reached to limit valu
Hello!
I'm building a forum and I'm thinking on save my "usersOnline" in one list(of T) cached on server!
I don't want do this under SQL because I don't want much Database Traffic.
Let me explain:
I have a Sub that insert members in my OnlineMembersList List or delete members if they LastActivity is bigger than 10 minutes (for example)
But when some user run this function and delete the other members I update my database the lastActivity by this member!
My problem is:
If 3 members are online and make the logout on same time, I loose the opportunity to check if there are any members to delete from the cached list and update DB with lastActivity of this members...
(if cached list deletes reached the limitTimeVlaue)
So I need a way to run one UpdateFunction exactly when the cachetime is reached(Because at this moment the cached list will be deleted..)
Any ideas?
|

October 15th, 2007, 09:36 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I think what you are looking for is "Cache callbacks". Search Google for some interesting information on this topic.
However, I think you may need to rethink your strategy. The cache is not the right location for this "must keep" data. The items you put in the cache can be trashed by the run-time whenever it sees fit, causing you to loose data about users that are still logged on.
Maybe application state or a database is a better location?
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|

October 15th, 2007, 09:56 AM
|
Friend of Wrox
|
|
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Imar!
I had this with database support on my first application but I'm thinking now to try "cache support"
I didn't know application state!
I saw this:
Quote:
quote:
Because an application and all the objects it stores can be concurrently accessed by different threads, it is better to store only infrequently modified data with application scope. Ideally an object is initialized in the Application_Start event and further access is read-only.
|
In my case I need to update my list everytime a user browse one page...
But if you think it's faithful than cache... I'm all hears...
What do you think about "only infrequently modified data" should be saved on application_state ?
My problem is because my wife is the forum administrator and she spent much time refreshing the MembersOnline page in order to see who is reading what! I just want to put this list elsewhere but not database! For me is equal cache or application_state! I just want the better.
Application state never expire?
|

October 15th, 2007, 10:16 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I agree with your quote on application state. That's how I look at it as well.
This also means you're stuck with the database option as the cache is unreliable by design.
How many users are we talking about? How many database updates?
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|

October 15th, 2007, 10:24 AM
|
Friend of Wrox
|
|
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
But the quote says:
"Because an application and all the objects it stores can be concurrently accessed by different threads..."
But remember that if I use Cache, database or Application_State I'll have this "problem"
I'm making multiple updates on one table/list that are being concurrently update/accessed!
I'm I right?
My application has +/- 10 members online (at the same time) for now...
In all my forumPages I have a UpdateFunction and I have 7 pages in my ForumsFolder
Thanks for your attention to this
|

October 15th, 2007, 10:35 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yes, correct. That's why, IMO, the database is the best option. You'll only update a record for the current user, so you're not likely to run into concurrency issues.
With the cache or application state, you do run this risk when two users try to change it at the exact same time.
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|

October 15th, 2007, 12:12 PM
|
Friend of Wrox
|
|
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Imar! I'm understood... DataBase will be!
BTW, what means "IMO" ? :)
Forgive this Portuguese guy!
|

October 15th, 2007, 12:37 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Great; good luck implementing it.
Doug is right; IMO is the not so humble version of IMHO which stands for In My Humble Opinion....
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: Read My Mind by The Killers (Track 6 from the album: Sam's Town) What's This?
|

October 15th, 2007, 12:46 PM
|
Friend of Wrox
|
|
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok! :)
Thanks for your IMO !
|
|
 |