 |
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0  | This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 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
|
|
|
|
|

May 23rd, 2007, 01:37 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Rating &ViewCount do not increment
Hi everyone.
Did anyone notice that the Rating and ViewCount do not increment in TheBeerHouse when you view it live. The same is the case when I view it locally. Whats wrong?
And can anyne tell me why Mr.Marco Bellinaso is not blogging? Its been a long long time I see him blogging? It seems he's busy. But I didn't see him blogging this year.
|
|

May 25th, 2007, 07:21 AM
|
|
Authorized User
|
|
Join Date: May 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hello,
excuse me for my english, i prefer french ;) ok.
it's normal that's rating and viewcount not increment, this is because the data you show is retrieved from cache :) if you disable cache from web.config it's will work fine but you lose performance.
cheers.
|
|

May 25th, 2007, 12:32 PM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanx for your reply.
When data is changed in database, the cache gets updated (the old cached data is purged out).
When a new comment/rating is added to some article and so the view count increases, it should get updated.
My point is why the system ins't showing the updated data?
|
|

May 26th, 2007, 05:45 PM
|
|
Authorized User
|
|
Join Date: May 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hello,
i'am agree with you. When data is changed in database, the cache gets updated (the old cached data is purged out) but only for InsertArticle, UpdateArticle and DeleteArticle methods and not for IncrementArticleViewCount and RateArticle why :
look at methods implementations, there no call to BizObject.PurgeCacheItems method.
public static bool IncrementArticleViewCount(int id)
{
return SiteProvider.Articles.IncrementArticleViewCount(id );
}
/// <summary>
/// Increments an article's view count
/// </summary>
public static bool RateArticle(int id, int rating)
{
return SiteProvider.Articles.RateArticle(id, rating);
}
but for DeleteArticle for example :
public static bool DeleteArticle(int id)
{
bool ret = SiteProvider.Articles.DeleteArticle(id);
new RecordDeletedEvent("article", id, null).Raise();
BizObject.PurgeCacheItems("articles_article");
return ret;
}
i hope that can help you .
cheers
|
|

May 27th, 2007, 02:07 PM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanx.
Okay.. so don't you think we should also discard the cache for rating and view count whenever these two gets updated?
Otherwise it looks strange to the visitors that their rating is not getting added imediately.
|
|

May 27th, 2007, 06:24 PM
|
|
Authorized User
|
|
Join Date: May 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
we purge only concerned article :). not tested but i think this will work.
/// <summary>
/// Increments an article's view count
/// </summary>
public static bool RateArticle(int id, int rating)
{
BizObject.PurgeCacheItems("Articles_Article_" + id.ToString());
return SiteProvider.Articles.RateArticle(id, rating);
}
cheers.
|
|

May 28th, 2007, 03:08 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
|
|
as an aside - you probably don't want to purge the cache in the IncrementArticleViewCount. the reason being that you'd always visit the database for each subsequent article (i.e. every visit to the article would cause a refresh as the incrementviewcount method would be called!!). better in this instance to just let the cache refresh by default (i.e. after 600 seconds). likewise, for the RateArticle, you might want to google 'ReluctantCacheHelper'. this little helper class let's you determine wheter the cache should be refreshed every time something changes or indeed whether the data is cached on the 1st query etc.. this is useful as it means that indexing spiders don't force your whole database into cache as they crawl the site.
as i said, google 'ReluctantCacheHelper' for full details, it'll make more sense when you read it in the author's page.
the link is:
http://weblogs.asp.net/gavinjoyce/pa...e-Pattern.aspx
jimi
http://www.jamestollan.com
|
|

May 28th, 2007, 05:29 AM
|
|
Authorized User
|
|
Join Date: May 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hello,
thank you for your reply and link
|
|

May 28th, 2007, 10:28 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks, both of you.
I guess things are now getting clear to me.
|
|

May 29th, 2007, 03:48 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
|
|
tectrix,
for the viewcount stuff, you could try the following:
public static bool IncrementArticleViewCount(int id)
{
//BizObject.PurgeCacheItems("articles_article_" + id.ToString());
Article article = Article.GetArticleByID(id);
if (article != null)
{
article.ViewCount++;
}
return SiteProvider.Articles.IncrementArticleViewCount(id );
}
this would mean that you'd be incrementing the object, rather than purging the database each time, therefore, each visit to the article would show an updated viewcount number without the database having to be visited.
jimi
http://www.jamestollan.com
|
|
 |