How To Setup Caching For A Page In .NET And Give It A Cache Key Dependency

Feb 15, 2011

How do I setup caching for a Page in ASP.NET and give it a cache key dependency? I am familiar how to do this with a UserControl, I set a Partial Caching attribute and then set

this.CachePolicy = new CacheDependency(..)

How would I do this for a Page? It does not have a CachePolicy object,

View 1 Replies


Similar Messages:

C# - Caching W/file Dependency: Static Var Vs. AspNet Cache Vs. Memcached

Sep 29, 2010

TL;DR: Which is likely faster: accessing static local variable, accessing variable stored in HttpRuntime.Cache, or accessing variable stored in memcached?At work, we get about 200,000 page views/day. On our homepage, we display a promotion. This promotion is different for different users, based on their country of origin and language.

All the different promotions are defined in an XML file on each web server. We have 12 web servers all serving the same site with the same XML file. There are about 50 different promotion combinations based on country/language. We imagine we'll never have more than 200 or so (if ever) promotions (combinations) total.

The XML file may be changed at any time, out of release cycle. When it's changed, the new definitions of promotions should immediately change on the live site. Implementing the functionality for this requirement is the responsibility of another developer and I.

Originally, I wrote the code so that the contents of the XML file were parsed and then stored in a static member of a class. A FileSystemWatcher monitored changes to the file, and whenever the file was changed, the XML would be reloaded/reparsed and the static member would be updated with the new contents. Seemed like a solid, simple solution to keeping the in-memory dictionary of promotions current with the XML file. (Each server doing this indepedently with its local copy of the XML file; all XML files are the same and change at the same time.)

The other developer I was working holds a Sr. position and decided that this was no good. Instead, we should store all the promotions in each server's HttpContext.Current.Cache with a CacheDependency file dependency that automatically monitored file changes, expunging the cached promotions when the file changed. While I liked that we no longer had to use a FileSystemWatcher, I worried a little that grabbing the promotions from the volitile cache instead of a static class member would be less performant.

(Care to comment on this concern? I already gave up trying to advocate not switching to HttpRuntime.Cache.)

Later, after we began using HttpRuntime.Cache, we adopted memcached with Enyim as our .NET interface for other business problems (e.g. search results). When we did that, this Sr. Developer decided we should be using memcached instead of the HttpRuntime (HttpContext) Cache for storing promotions. Higher-ups said "yeah, sounds good", and gave him a dedicated server with memcached just for these promotions. Now he's currently implementing the changes to use memcached instead.

I'm skeptical that this is a good decision. Instead of staying in-process and grabbing this promotion data from the HttpRuntime.Cache, we're now opening a socket to a network memcached server and transmitting its value to our web server.This has to be less performant, right? Even if the cache is memcached. (I haven't had the chance to compile any performance metrics yet.)On top of that, he's going to have to engineer his own file dependency solution over memcached since it doesn't provide such a facility.

Wouldn't my original design be best? Does this strike you as overengineering? Is HttpRuntime.Cache caching or memcached caching even necessary?

View 2 Replies

MVC :: How To Cache MVC Page - Donut Caching With .NET

Oct 1, 2010

[OutputCache (Duration=20, VaryByParam="None" )]
public ActionResult display()
{}

This code cache whole page.But, my site has user infomation on top like this ASP.net. The user info "Signed as userid | Edit Profile | ..." section should be changed when user sign in/out. But rest of the page is always same and it's good to Cache.

If the above code is used, the user info on top also cached and give wrong info to user.

View 11 Replies

Passing Data From Page To Page Using System.Web.Caching.Cache?

Apr 23, 2010

I'd like to pass data from one asp.net page to another. I've seen that using System.Web.Caching.Cache is a good way to accomplish this. I'm wondering if it's a good way to do it and also is there any cleanup or other things I need to keep in mind when you the Cache?

I'm not passing very much, at most two integers.

View 2 Replies

C# - Implement System.Web.Caching.Cache Object In A Controller To Cache Specific Query?

Mar 29, 2010

Is it correct to implement my caching object like this in my controller :

[code]....

And I Use it like this :

[code]....

View 1 Replies

How To Use Data Caching With Sql Dependency

Dec 2, 2010

We store the location information in a table. Numbers of records are over four thousand. This table structure is self-recursive. In our web project, we use dropdownlist control to populate all these locations. We got performance slow problem. So googling about Caching, we consider to use Data Caching with Sql Dependency. However, not found yet a full-covered sample in .NET 2.0 and SQL Server 2005 or 2008.

View 1 Replies

Custom Server Controls :: How To Programmatically Cache A Server Control And Add A Cache Dependency?

Feb 11, 2011

I have a server control that I developed which generates navigation based on a third party CMS API. Currently I am caching this control using the PartialCaching attribute. The CMS uses cache key dependencies to invalidate the cache when a user makes an edit, however in the case of my server control it does not get invalidated and the updated navigation will not show up until the cache expiration set by the PartialCaching attribute.Here is my two part question:

What is the proper way to programmatically cache a server control, without using the PartialCaching attribute, and adding a cache key dependency?

Is it possible to continue to use the PartialCaching attribute and add a cache key dependency?

View 2 Replies

Architecture :: Distributed Caching / Keeping Cache In Sync Between Multiple Webservers Or Even Better Farm Cache Management To Another Server?

Feb 26, 2010

I've got a web application that runs of a state server. It looks like soon it may need to distributed and there will be two web servers behind a load balancer.

This works great for session state but my next challenge is Cache

My application leverages heavily of cache. I understand ASP.Net 4.0 will be offering more here but nothing much has been said about the how too.

There are two challenges that I face

1). Each webserver will have its own copy of cache whereas it would be more efficient to put this to a third server the same as session state is put to state server.

2). The real challenge is keeping cache in sync if a simple dataset derived from the database is changed my code dumps that cache item and reloads the cache. That's all well on one webserver but webserver number two wont know to drop that particular cache item and reload it. This could cause some unexpected problems in the application.

For scenario number 2 I could attempt to do some smart coding so server number two knows to dump the cache and reload it.

My guess is someone else has already been here before and there's probably a better implementation approach rather than writing extra code.

Does anyone know how I could achieve the goal of keeping Cache in sync between multiple webservers or even better farm Cache management to another server?

View 2 Replies

MVC :: Output Caching And Query Dependency?

Sep 21, 2010

I plan to use output cache for my page and also specify sql dependencyi succeded in doing it the following way

[Code]....

Suppose if i want to implement a dependency on the sql query , i create an sqlcache dependency object and specify the sql command to it.Set the notifications .But how do i add this sqldependency to the output cache?For example: if i need to add a file dependency, i give something like Response.AddFileDependency ("filepath"); is there any similiar command available for sqldependency as well? I'm confused about this because, most of the examples i've looked into, does a cache.insert , which defeats my purpose as it's object caching and not output caching. In a nutshell, is it possible to attach a sqlcachedependency to o/p cache inside the controller action

View 3 Replies

How To Enable SQL Cache Dependency

Jul 5, 2010

I think there are some steps to enable SQL Cache Depdndency :Enabling notifications, changes in web.xml and then using Cache Dependency object.

View 2 Replies

SQL Server :: Command And Caching / Cant Use Dependency As Query Doesnt Fit The Rules?

Feb 25, 2011

asp.net 2.0 MSVS2005 vb.net

I do this..I pull up a SQL multi view SELECT query (thats a stored proc with 3 SELECT statements in it).

[Code]....

I then run thru dr and dr.nextresult and populate controls with it.

The above is fast.

QUESTION : Can I cache at the SQLcommand level in the above code ?

NOTE: I can NOT use SQL dependency as my query doesnt fit the rules

View 1 Replies

Cache Dependency On File - Not Firing The Event?

Sep 27, 2010

I configured cache dependency on a file on the server, the cache dependency event stops responding to file changes once in 2 or 3 days. After I perform IISReset on the server, it works fine.

View 1 Replies

SQL Cache Dependency Not Working With Stored Procedure

Feb 22, 2010

I can't get SqlCacheDependency to work with a simple stored proc (SQL Server 2008):

create proc dbo.spGetPeteTest
as
set ANSI_NULLS ON
set ANSI_PADDING ON [code]...

And here's my ASP.NET code (3.5 framework):

-- global.asax
protected void Application_Start(object sender, EventArgs e)
[code]....

View 4 Replies

SQL Server :: Unable To Connect To The SQL Database For Cache Dependency Registration

Aug 25, 2010

i am trying to setup SqlCacheDependency with MS SQL Server 2008, i am using
aspnet_regsql.exe cmd line tool. I am able to enable it for database but when try to do it for table i get the following error message.Enabling the table for SQL cache dependency.

.An error has happened. Details of the exception: Login failed for user 'myUserName'.

Unable to connect to the SQL database for cache dependency registration.

View 1 Replies

HttpHandlers / Modules :: Cache Images - Page Takes To Long Due To Images Not Caching?

Mar 31, 2010

I've been trying to get image caching working for the last 8 hours and I keep the same problem time and time again, I'm trying to cache Images at the moment and then when thats succesful, apply this to cache my js and css files. I have at the moment Sql Dependancy caching working on my dynamic pages but the page still takes to long due to images not caching.

What I have tried is going to IIS7 Management and adding HTTP Response Header for the images folder and setting various things for the cache control.i dont care how long it caches it on the client or on the proxy servers i just would like it to check when the file was modified and compare it with the one in the client or proxy cache and if they are different then fetch the new image which has been ftp up. i could solve this by changing the image name but the thing is the image name is generated when they are ftp'd to the site by an application and the name is a direct reference to the product so i cant change the name each time, as it would mean making a lot of otherpages accross the board.

so What i would like, is to set and expiry date of lets say 32 days or more on the images and then check to see if they have changed by date modified or some other way of checking(Etags maybe) I'm not sure, if they have changed on the server then redownload and recache them, I tried using post-check and pre-check together but that just permantly cached them, so when i change the image the only way it would display the new image is to just hit F5.

In Brief, how can i Cache images, on the client machine/ proxy cache and recache them when the modified date of the file has changed.

View 4 Replies

State Management :: SQL Server Based Cache Dependency Without Data Source Control?

May 29, 2010

I want to use SQL Server based Cache dependency without data source control.How can I do it?I am binding data to grid through code.

View 5 Replies

How To Setup Silverlight Xap Caching To Work The Same In All Browsers

Dec 20, 2010

I have a SL app that can be run in-browser or out-of-browser. I want the browser to:

Cache the xap file Load the xap from the cache if it has not changed or re-download it if it has changed.

More details

Setting a future expires header obviously solves the caching problem but then I cannot force the user to download the latest version. Normally I would just add a querystring to the url (eg url?v=1) but I cannot do this as this breaks the out-of-browser functionality. eg the app thinks it is not installed when in fact it is.

no cache

If I set Cache-Control to no-cache, Chrome and Firefox correctly send a request to the server for the xap but use the cache if a 304 is returned. IE8 just downloads the file again as does Safari.

must-revalidate

Setting Cache-Control to must-revalidate again works correctly in Chrome and Firefox but Safari always downloads the xap again while IE8 always uses the cache.

View 1 Replies

Caching - How To Cache A List Of Objects

Jan 23, 2010

I have a List of objects in an asp.net page. when the page loads in the browser for the first time, I fetch data from the database, create objects with those data and populate the list. All these are done inside the page load event handler. Now when the page is posted back to the page, the previous list is gone, since the variables were all freed.

How can I cache that List, so that when this page is posted back, all my objects are available?

View 5 Replies

C# - Caching Through HttpContext.Current.Cache Or Just A Static?

Mar 28, 2011

Last night I wrote up my first IHttpModule to do some request processing. I'm using a regular expression to inspect the raw url. The IHttpModule will be called on every request, so it seems reasonable to do some sort of caching of the regular expression object to prevent creation of it on every request.

Now my question... what is better: use the HttpContext.Current.Cache to store the instantiated object or to use a private static Regex in my module?I'm looking forward to the reasons why. Just to clarify: the regex will never change and thus always be the same thing.

View 3 Replies

Caching - How To Hold Current Date In Cache

Jul 28, 2010

I am building a web application using asp.net (c#) and lingtosql. When I perform update operations on my db I update my classes. I use gridview to bind to update information. When I relay solely on the database the page's take very long to load. When I relay solely on the cache, I have old data. What workarounds do I have for have asynchronous cache updating, yet not overload the database with endless requests (I'd like to update the cache only if there has been a change in the database itself, and perform the update operation asynchronously).

View 1 Replies

Caching - What Is The Default Serialization Used By The HttpRuntime.Cache

Jan 29, 2010

what the default serialization used by the ASP.net HttpRuntime.Cache is? Is it Binary, XML, something else?

I am populating a generic List with multiple objects of the same custom type. The custom type is a POCO, there is nothing special about it. All of its properties are public with { get; set; }, it is public, it has no inheritance, it has no interfaces. In fact it is much less complicated than many other objects which we are caching which work without issue. I have tried adding the [Serializable] attribute to the custom class and it has no effect.

I add the list to the cache with a unique key. The list has been verified as populated before it is inserted into the cache, the objects in the list have been verified as populated as well. But when the list is pulled back out of the cache it is an empty list (NOT NULL), it simply has no items in it. This means that the list is being added to the cache and is retrievable but for some reason the cache is having issues serializing the objects in the list.

I just find this freaky weird since I have another list of custom objects which are much more complicated (consisting of Inheritance, Interfaces, and also containing Properties which are generic lists of other complex objects) and the caching of those lists work without issue.

Both the working and non-working list are being managed in C# classes outside of the ASP.net user controls which consume the cached data. Both of these cache handling classes call the exact same Cache Manager class singleton instance which wraps the HttpRuntime.Cache to provide typed methods for pull and pushing objects into the cache.

Here is the class

[code]....

View 2 Replies

Caching - Cache Render Of Calendar Control?

Sep 8, 2010

We display an ASP.NET calendar control and update the color and if the day is enabled with the DayRender event. This process is a bit slow so I'm trying to map out a strategy to cache the results of the all the DayRenders. Basically take a snapshot of the calendar and cache it for X minutes. Where would I hook into the page/control workflow to accomplish this goal?

View 1 Replies

Caching - Controlling Output Cache Memory Usage?

May 17, 2010

I would like to use output caching with WCF Data Services and although there's nothing specifically built in to support caching, there is an OnStartProcessingRequest method that allows me to hook in and set the cacheability of the request using normal ASP.NET mechanisms.

But I am worried about the worker process getting recycled due to excessive memory consumption if large responses are cached. Is there a way to specify an upper limit for the ASP.NET output cache so that if this limit is exceeded, items in the cache will be discarded?

I've seen the caching configuration settings but I get the impression from the documentation that this is for explicit caching via the Cache object since there is a separate outputCacheSettings which has no memory-related attributes.

Here's a code snippet from Scott Hanselman's post that shows how I'm setting the cacheability of the request.

[code]....

View 1 Replies

System.Web.Caching.Cache Doesn't Seem To Refresh Itself On Time

Jan 27, 2011

I am using System.Web.Caching.Cache in an assembly used by my website.

I have set some key expiration (absolute expiration) to be 10 seconds (just for debugging).

I have also set a callback upon key removal.

The problem is that I see that the cache is getting refreshed after something like 20 seconds and not 10.

I am using HttpRuntime.Cache for this.

I would like to show a code sample, which can shed more light:

[code]....

What could be the problem ?

View 2 Replies

State Management :: Where Is The System.Web.Caching.Cache Actually Stored

Nov 25, 2010

I am using this to store my user information for authentication. I'd like to know where this is actually being stored? I know that people suggest to store the Session state in SQL. Is this necessary for the Cache as well?

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved