C# - How To Implement VaryByCustom Caching
Mar 15, 2011
I'm trying to implement functionality to cache certain pages depending on the host. This is because I can have multiple versions of a page which have the same parameters, and where the only difference in terms of a request is the host that is being requested. So, for example these two URLs will request the same page, but they are styled differently:[URL]and [URL]
I'm going through the example outlined here:[URL]but it's not making sense to me.
I've added this to my global.asax:
public override string GetVaryByCustomString(HttpContext context, string arg)
{
if (arg == "host")
{
return "host=" + context.Request.Url.Host;
}
return base.GetVaryByCustomString(context, arg);
}
and the example states "To set the custom string programmatically, call the SetVaryByCustom method and pass it the custom string to use", with code similar to the following:
Response.Cache.SetVaryByCustom("host");
The problem is I'm not sure what to do with this. I've added the previous line to MvcApplication_EndRequest because it seems like it makes sense, but I don't think this is right because when I set breakpoints in GetVaryByCustomString they never get hit.
[Code]....
View 4 Replies
Similar Messages:
May 15, 2010
how to implement caching in wcf service using System.Web.Caching
View 2 Replies
Apr 4, 2011
Can I Implement Caching in MVC, If so how? I wanted to implement Cache in Controllers
View 2 Replies
Sep 29, 2010
explain me how to implement SQL Dependency Caching in Asp.Net?
View 3 Replies
Mar 15, 2011
I use a Masterpage (asp.net webforms) on my site and I woluld like to implement caching of some static files, like javascript, css etc.
I've tried adding the following to my page_load (in the masterpage) but when I use Fiddler the static files are still under "no-cache".
protected void Page_Load(object sender, EventArgs e)
{
// Set cache for 1 hour on all computers and servers.
// ... Proxies, browsers, and your server will cache it.
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0));
}
What am i doing wrong here?
View 1 Replies
Sep 25, 2010
I have aspx page with a user control. I want to implement caching for the entire page except the user control.
View 2 Replies
Jul 14, 2010
i am in the process of developing a social networking web app using asp.net mvc 2 and asp.net 3.5 sp1.I have implemented user authentication and role management (like admins, etc...) and i was wondering how i could implement page caching in such a scenario based on the user currently logged in.
Note that the web app page urls may, or may not contain the name of the user authenticated and that there are also pages available to both authenticated and both authenticated users.
What i would like to avoid is to make a cache version of a page for an authenticated user, available to a non authenticated or to another authenticated user.
View 3 Replies
Dec 3, 2010
How to implement caching to a dropdown list
View 2 Replies
Aug 18, 2010
How do I implement partial page caching with an AdRotator control? I know it's supposed to do it automatically, but I'm using the AdCreated event to handle stats, and this seems to cause the ad to be cached along with the rest of the page.
View 4 Replies
Nov 15, 2010
I'm using output cache for a web site with login system. I have global pages which can be accessed by every user. These pages are cached and also use a master page.
<%@ OutputCache Duration="3600" VaryByParam="none" VaryByCustom="userid" %>
I'm storing user login details in a session. My global.asax file is here:
public override string GetVaryByCustomString(HttpContext context, string arg)
{
string result = String.Empty;
if (arg == "userid")
{
object o = Session["UserID"];
if (o != null) { result = o.ToString(); }
}
else { result = base.GetVaryByCustomString(context, arg); }
return result;
}
I have a panel in master page which is visible for authenticated users. When a user logins and views public page A another guest user also sees authenticated user panel on page A. If guest first view page A then authenticated user does not see panel on page A. What part of my code is wrong? I'm using VaryByCustom for first time..............................
View 1 Replies
Apr 15, 2010
I want to use an Enum value for the types of VaryByCustom parameters I will support, is it possible to do this?
I tried setting it in the page itself
<%@ OutputCache Duration="600" VaryByParam="none"
VaryByCustom='<%=VaryByCustomType.IsAuthenticated.ToString(); %>' %>
But this returned the entire literal string "<%=VaryByCustomType.IsAuthenticated.ToString(); %>" inside my global.asax is there any way to do this either on the page itself or from the codebehind? Or is this just something I have to accept is purely magic strings and nothing I can do to add type safety to it?
View 1 Replies
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
Jun 14, 2010
I have a page with a number of user controls, In one of my user controls I have a button event. I turn on output cache for the user control that has the button and vary by control using the ID property of a hidden field control in the user control. whenever I turn on the output cache my button event doesn't fire.
View 2 Replies
Dec 5, 2010
I want to use caching technique for .js,.css and images( to avoid round trips and to improve performance of page load) .So, on IIS 7 using Http Response Header, i set Content Expriation to 7 days.Now, on browser its caching which is avoiding round trips for static content ...which is good sign.Now, i modified one of the .js file and i deployed that .js file on server and due to caching my new code is not reflecting on client machines .So i tried lot of ways and here is what i tried after deployment of new .js file After deployment of new .js file
1) I manually delete all the browser cache(cookies,urls,forms,page content etc) on internet explorer
2) used ctrl + f5 to get refresh
3) again on IIS i went back Http Response Header section and set Content Expriation to never
4) stopped the website and restarted
5) on web.config file tried this only
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
6) Also tried to set this on .aspx page
<HTML>
<HEAD>
<TITLE>---</TITLE>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</HEAD>
<BODY>
7) tried to set this on .aspx.cs file
<% Response.CacheControl = "no-cache" %>>
<% Response.AddHeader "Pragma", "no-cache" %>
<% Response.Expires = -1 %>
My target browser is IE.None of them worked,Finally i renamed my .js file to different file name and changed code to make use of that new .js file ..but no luck on this too .Because what i set intially for 7 days still my client machine remembers that.
How do i tell IIS server to refresh cached content code , when some thing got changde on .js or .cssfiles?
View 1 Replies
Mar 15, 2010
I asked a question a while back on here regarding caching data for a calendar/scheduling web app, and got some good responses. However, I have now decided to change my approach and stat caching the data in javascript. I am directly caching the HTML for each day's column in the calendar grid inside the $('body').data() object, which gives very fast page load times (almost unnoticable). However, problems start to arise when the user requests data that is not yet in the cache. This data is created by the server using an ajax call, so it's asynchronous, and takes about 0.2s per week's data.
My current approach is simply to block for 0.5s when the user requests information from the server, and cache 4 weeks either side in the inital page load (and 1 extra week per page change request), however I doubt this is the optimal method. how to improve the situation? To summarise:
Each week takes 0.2s to retrieve from the server asynchronously. Performance must be as close to real-time as possible. (however the data is not needed to be fully real-time: most appointments are added by the user and so we can re-cache after this) Currently 4 weeks are cached on either side of the inial week loaded: this is not enough. to cache 1 year takes ~ 21s, this is too slow for an initial load.
View 1 Replies
Aug 20, 2010
I am just trying to understand the basics flow to the MVC framework by putting in some breakpoints in the beginning of the actions of a couple of controllers.
One break point is at the HomeController/Index action where it just returns View() of the "Welcome to MVC". The Second break point is at a SecondController/Index action where it uses the Entity Framework and returns a View() of a list from the db.
When I run this in debug, it breaks at the points I expected when I go from Home page to the Second page controller and back to Home. However, when I go to the Second page again, it doesn't break at all? Is the results of the Second page being cached and how and where? How do you trigger for it to get check if data is old?
I check to see if the persistence is done on the db, by changing the value of a field on the db side and it still did not cause it to break on that action and displays old information in the view. I am concerned because it is displaying incorrect values on the UI. I do not have the OutputCache attribute above this action or specified any cache on my web.config.
View 2 Replies
Mar 19, 2011
I have a .NET website which queries the DB using Entity Framework every 3 seconds for the status of the transaction using AJAX and updates the page. This status is set by an external client using a RESTful webservice hosted on another server. I want to avoid hitting the DB every 3 seconds for each transaction so want this information cached in memory. The REST webservice updates the cache and website reads from it. Is there any FOSS or commercial Out of Process Shared Cache library that I can use to speed up the performance?
View 3 Replies
Aug 13, 2010
I have a table that stores songs and plays counter.
Here's the code:
//Increse plays counter
string ip = Request.UserHostAddress;
if (!string.IsNullOrEmpty(ip))
{
if (Cache["plays:" + trackID + ":" + ip] == null)
{
tracks.IncreasePlaysCounter(trackID);
Cache["plays:" + trackID + ":" + ip] = true;
}
}
I wonder what would be a better practice, store many cache items(like this) or store one item like a ArrayList that would contain the users who already heard that song. Is there any difference?
View 2 Replies
Mar 18, 2010
Is it possible to do data caching in client-side in asp.net and c#.net iam planning to cache a dataset.
if so provide a sample?
View 2 Replies
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
Mar 17, 2011
My web application is using the asp.net cache object to store data from the database. I am looking for an elegant to invalidate cache objects but haven't come up with anything elegant yet. It is easy to invalidate a single record or a list of all records in a single table, by keeping track of their cache keys. However I may have any number of lists of subsets of a table's data. I would like to invalidate only the cache records of the lists that contain a particular record, when that record changes. I don't want to have to invalidate all the lists of data for that table if only one of the lists contain that record.
View 1 Replies
Dec 6, 2010
I have an application written in asp.net c# and hosted on IIS6. There are an 'Image' folder with 3-subfolders. These folders contained images of type 'jpg','gif','png' etc. Images are very huge in size and in numbers. On the application every page has some images needs to open/show, due to the size of images my application get slower and slower.
I know there are some techniques to Cache image folders at client machine or some other methods. I have no access on IIS. So, I need some httphandler or httpmodules which provide something like Image-caching.
I tried this : codeproject.com/KB/aspnet/CachingImagesInASPNET.aspx The problem is I have to add an extra extension '.ashx' to every image link. There is no problem with images are loading dynamically but it has trouble with images need to embose a manual link. Also, this is working fine upto around 1000s images.
View 2 Replies
Jun 30, 2010
What are the advantages and disadvantages of using caching in an asp.net application?
View 2 Replies
Jan 15, 2010
Details:
I am using visual studio 2005 on windows xp sp3. The website is stored on file system. I used subversion to checkout the code from the server.
Here is the issue:
When I run the application for the first time everything is fine. But when I makes changes in the application then I should just be able to see those changes by reloading the page in browser. But it's not happening. I have to stop the development server and re-run the application which will start a new instance of development server and now I can see the changes. This takes like 3-4 minutes and it's a lot of waste of time which I can't afford.
For my fellow developer who is here for a long time everything is just working fine. He can just modify the page and reload the page in browser to see the changes.
Reading some forums on web, I tried to clear the cache of my browser (IE, Firefox) and it's not working. So, it's not a browser's cache issue. It's related to cache in development server.
View 3 Replies
Mar 16, 2011
Maybe this is dreaming, but is it possible to create an attribute that caches the output of a function (say, in HttpRuntime.Cache) and returns the value from the cache instead of actually executing the function when the parameters to the function are the same?
When I say function, I'm talking about any function, whether it fetches data from a DB, whether it adds two integers, or whether it spits out the content of a file. Any function.
View 5 Replies