C# - Invalidating The HTTP Cache On Read Only Front Servers?
Mar 24, 2010
We have a CMS system and in the production mode a number of servers only have read-only access to the content (with a few exceptions) and the editors for the site work on the content on servers behind it (which are not available to the public).
We're caching the content quite a long time on the front servers, but sometimes we want the content the editors publish to be available for visitors instantly. What is best practice for invalidating the cache in those cases?
I think it is a problem that SqlCacheDependency may invalidate a cache item while it is being set:
function getCacheItem() if cacheitem is empty cacheitem = something AND AT THIS POINT SqlCacheDependency INVALIDATES THE cacheitem end if return cacheitem end function
how can we prevent this? Is it somehow possible to specify a ReaderWriterLockSlim for the SqlCacheDependecy to use?
We have a wfc layer that wraps the business classes and database access and use a client that lives on the database layer. Amongst our group we are attempting to form standards. Some want to have the client call the web method and pass the page they are requesting and the page size. Pass that to the database and then page in SQL Server use RowNum.Some want to cache the full list of objects in http cache on the service tier and page in memory. They concern here is memory use on the server.
Which would be best for a medium number of users with potentially large number of records to manage (say 30K) Is it better to cache them all in memory and work from there or page at the database as the application scales?
We have a web application that is storiing all site data in HttpRuntime.Cache. We now need to deploy the application across 2 load balanced web servers. This being the case, each web server will have its own cache, which is not ideal because if a user requests data from webserver1 it will be cached, but there next request might go to webserver2, and the data that their previous request cached won't be available. Is it possible to use a shared-cache provider to share the HttpRuntime.Cache between the two web servers or to replecate the cache between them, so that the same cache will be available on both web servers?
We are working on a web application that is distributed across 3 load-balanced web servers. A lot of the data we retreive via NHibernate is stored in System.Web.Caching.Cache.
System.Web.Caching.Cache does a lot to increase the responsiveness of an application, but there are a few issues that we don't exactly know how to resolve, such as
when a user requests data on server1 that data is cached on server1, but for their next request, the load balancer might direct them to server2. That data they requested on server1 is no longer available, and server2 will have to request it from the database again. If the user does something on server1 to invalidate the cached data, the cache is flushed on server1. However the original cache is still available on server2 & server3, so when the user submits a subsequent request and they're directed to either of the other servers, they are going to be presented with invalid data.We have applications that update data (such as performance data) on a regular basis. When the performance data is updated we want to flush this from the cache so when a user requests the data again, they're presented with the latest data. How can we get these applications to flush the cache on 3 web servers?
What are the best ways to resolve these issues?
Should we have cache stored on a separate server such as we could to for HttpContext.Session with a SessionState server?
Is there a way for us to set a Cache Dependency on the Cache in the other 2 servers?
Is it possible for us to implement a Cache Dependency on the actual database tables or rows? When these change the cache is flushed? -- or could we set up a database trigger to flush the cache somehow?
I am having issue with cache-control. I have one IIS website with multiple host headers. When you browse site number 1 then cache will be set for this site, when you open browser again and go to 2nd site you will see content from first site. How can I determine cache content based on the site user visits? Everything working fine when you have 1 site and host header related to SAME site.
//Set Cacheability if (!Context.User.Identity.IsAuthenticated && _activeNode.CacheDuration > 0) { var eTag = GetETag(_activeNode); HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
I am working on a asp.net web site, like normal user, we use asp.net developer server during coding and testing.Today, I found the firefox not cache any static file of my site, since our application is pretty big, it made page load time very slow.I checked firefox about:cache, all the static file cache setting looks like
Key: http://localhost:26851/App_Layout/icons/actions/email/folder.png Data size: 871 bytes Fetch count: 1[code]...
The expires date is set back to 1969-12-31, I believe that's the reason why they are loaded very time.I am using Visual studio 2008, windows 7 machine. The application works fine in IE, the contents are properly cached.
I have a navigation on my site that retrieves it's links from xml file..Does asp do this everytime a link is clicked on my site..I'm using a master page and the navigation code within the master page is below..So is the xml file opened and read each and every time? any way to cache it or something.below is my code
I am trying to set up my web site on a stand alone server using Windows Server 2003 with IIS 6 which will access SQL server database (2008) on windows 2008 R2 server (also not in the domain) I am using form authentication and I have configured a custom identity account in IIS6. The local account is on both servers with same password and I have registered the account using aspnet_regiis.exe -ga The application pool in my iis6 has the custom local account set as the identity and my web.config file has the appropriate tags in the system.web element <identity impersonate="true" />
The problem is the local account does not seem to get passed to the sql server. Right now my iis settings are anonymous access (using the local acct vs isr) and no authentication specified under that - I did try Integrated and basic but it prompts for the username and password which I do not want. One article I read stated this: windows authentication does not support delegation (passing credentials from one server to another) and is limited to the one hop rule, only a primary token can be passed to a second server. windows authentication on iis (all versions) gives the thread a secondary(impersonation) token which can not be used to access any network resouce
I am using an Zencoder API to transcode video files. Once the job is completed they will do a HTTP POST with XML or JSON data containing the Job ID and other info to the url we provide.
So if URL is www.abc.com/GetZencoderResponse.aspx or .ashx, how can I read the data they post?
excuse me for the underlines, i thought that would make my query stand out.
I've tried to write my own HttpModule (IHttpModule) that adds a Header like that:
public class MyModule: IHttpModule { public void Init(HttpApplication c) { c.BeginRequest += delegate{c.Response.AddHeader("MyHeader", "MyValue");}; } public void Dispose(){} }
I have a very simple query. I have added custom header to my website. Now I want to read the custom header. I am using IIS 6.0 on windows XP. I have already tried using using the Request.ServerVariables and and Request.header method. But none of them give me the custom header added to website.
I would like to read all content that's been written to the output stream. I'm attempting to do this using an HTTP module, and it seems like the obvious timing would be when handling the PreSendRequestContent event.
However, if the output stream seems to be set to write-only, as I can't read using a StreamReader. Is there a way I read and re-write the content without writing my own IIS module?
Is it possible to validate a user's Username + Password without logging them in? I understand a usual login block will look like this:
[code]....
With the Membership.ValidateUser() call setting the cookie for the response.
However, there are some additional checks I'd like to perform after the password is confirmed. (Pulling out an expiry date for that user, for example).
Is there a way to do it without just calling FormsAuthentication.SignOut(); after invalidating the page?
I'm having a problem trying to delete the form authentication ticket (.ASPXAUTH) from the server side. It would be the same to delete or invalidate the ticket so the client could not reuse it.
So far, the only solution I've found is to delete the ticket from the client side (through a "Set-Cookie: .ASPXAUTH=;") but nothing seems to be implemented and/or working for doing so in the server side. The final idea is that if someone steels that ticket
In particular, I'm working in C# but as it's rellated to the Dotnet Framework any implementation of the solution would be OK; I tried all the possible things and nothing worked out, even invalidating the session but nothing.
Since I don't want my sessions to be removed unless the session has been abandoned either via code or Session Timeout...For eviction, I would think "None" and for expireable, I would think False.I have tested and calling Session.Abandon does remove the object from the cache. I have also tested to see if by extending my session, the session object in cache is also extended. This does seem to work the "correct" way.
We have a data driven ASP.NET website which has been written using the standard pattern for data caching (adapted here from MSDN):
public DataTable GetData() { string key = "DataTable"; object item = Cache[key] as DataTable;
[code]...
The trouble with this is that the call to GetDataFromSQL() is expensive and the use of the site is fairly high. So every five minutes, when the cache drops, the site becomes very 'sticky' while a lot of requests are waiting for the new data to be retrieved.
What we really want to happen is for the old data to remain current while new data is periodically reloaded in the background. (The fact that someone might therefore see data that is six minutes old isn't a big issue - the data isn't that time sensitive). This is something that I can write myself, but it would be useful to know if any alternative caching engines (I know names like Velocity, memcache) support this kind of scenario. Or am I missing some obvious trick with the standard ASP.NET data cache?
we have so many parameters that the cache key is several hundred characters long. is there a limit to the length of these cache keys? Internally, it is using a dictionary, so theoretically the lookup time should be constant. However, I wonder if we have potential to run into some performance/memory problem.
I have use Nhibernate in my MVC Project by me known, Nhibernate have cache on Session and Object. now, I want use HttpContext.Current.Cache (system.web) for cache data something in project. my code same that have problem, haven't it. and that's right or wrong.
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?
I need to enable caching in my asp.net application, but I do not want to use the webserver's memory for holding cache objects. If I add the page directive for output caching will the page be stored in the asp.net cache object?