UserControl: How To Set Output Cache Duration Programmatically?
Mar 22, 2010UserControl: How to set Output Cache duration programaticaly?
View 2 RepliesUserControl: How to set Output Cache duration programaticaly?
View 2 RepliesI want duration to be configurable from Web.config file, so user can alter the output caching after deployment.
For achieving such puropse i need quuivalent C# codebehind snippet of following ASP.NET markup?
<%@ OutputCache Duration="120" VaryByParam="CategoryName" %>
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?
I am deciding to output cache my page and i need to set duration as never expiring. how can i achieve this? Also if i do not specify any location, where will the cache get stored? client or server? Ram or hard disk ?
View 4 RepliesI 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?
View 2 RepliesI've built a Repository that gets user details
Public Function GetUserByOpenID(ByVal openid As String) As User Implements IUserRepository.GetUserByOpenID
Dim user = (From u In dc.Users
Where u.OpenID = openid
Select u).FirstOrDefault
Return user
End Function
And I'd like to be able to pull those details down IF the user is logged in AND IF the cached data is null.
What is the best way to create a User object that contains all of the users details, and persist it across the entire site for the duration of their visit?
I Was trying this in my Global.asax, but I'm not really happy using Session variables. I'd rather have a single object with all the details inside.
Private Sub BaseGlobal_AcquireRequestState(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.AcquireRequestState
If Session("UserName") Is Nothing AndAlso User.Identity.IsAuthenticated Then
Dim repo As UrbanNow.Core.IUserRepository = New UrbanNow.Core.UserRepository
Dim _user As New UrbanNow.Core.User
_user = repo.GetUserByOpenID(User.Identity.Name)
Session("UserName") = _user.UserName()
Session("UserID") = _user.ID
End If
End Sub
You know I have the way to Cache the data I've got from the SQL Server over data caching. In addition I can output cache web user controls.Whats about a web user control contains data from a SQL database? Does it make sense to cache the data and also cache the control?What is the best solution for the combination of these two components?
View 1 RepliesI 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?
I'm running an ASP.NET MVC website where several page controllers are decorated with an output cache attribute like:
[OutputCache(Duration = someduration..., VaryByParam = "*")]
These are typically forms where some lookup data are drawn from a database. These data change rarely, so the cache duration is typically set to 24 hours. Anyway, my question is: when the sql server is updated with new data in this area, is there a way of forcing such pages to "refresh" rather than keeping the cached output? Or if this cannot be done, is there at least a way of clearing the whole cache for the website?
I've got a website that has a number of host headers. Depending on the host header, the results are different - both visually (theme'd) and data.
So lets imagine i have a website called 'Foo' - that returns search results (original, eh?).
Now, the same code runs both sites. It is physically the same server/website (using Host Headers) :-
[URL]
And the data is different for the same search result, based on the host name (ie. us results for [URL] results for [URL]
SO .. if i wish to use OutputCaching .. can this be handled / differ by the host name?
Suppose i have an controller action that i would like to output cache.
public class HomeController : Controller
{
[OutputCache(Duration=10, VaryByParam="none")]
public ActionResult Index()[code]....
I need to dynamically set dependency to an external file inside the code. How can i do that?
I have different urls that points to the same code
www.url1.com
www.url2.com
I need to use the cache, but if the asp net cache is enabled when someone access to www.url1.com next person accessing www.url2.com could get the previously cached data (www.url1.com)
I need to have ALL caches activated except this one.
I implemented : <%@ OutputCache Duration="43200" VaryByParam="none" location="Server" VaryByCustom="RawURL" %>
I have got a sitemap.xml with all url(about 12000) possible in my site.
I would now if it's judicious to create an application that will parse my sitemap in
order to request all url?
The Goal is caching all my web site to increase velocity.
I precise my question :Each page take about 10 sec to be created and the cache duration and cache duration is 12 hours
IIS7, WINDOWS WEB SERVER 2008, ASP.NET 4.0 Does the output cache work when using webgarden?
View 1 RepliesMy web client requires client-side output caching since it makes use of its own Back and Forward buttons (which basically just call the browser back/forward buttons).
The issue I'm having, however, is (of course) when the user signs out of the app. The client-side output cache remains so anyone can click the "back" button and it appears to be signed in again. I've researched a few solutions, but most involve server-side output caching or no output caching at all.
I've had success with server caching and HttpResponse.RemoveOutputCacheItem, but unfortunately I need the client side caching.
Is it at all possible to clear this client side output cache upon logging out?
On our website we use standard asp cache with duration set to 5h.
It works fine, but sometimes the publisher add some special content that need to be showed impatiently on many different sub-pages (example some promoted article).
That's what I need to do it's easy to use page like this:
[URL]
I want to clear SERVER SIDE CACHE.
I'm trying to cache a complex page with lots of controls on it so that if the user navigates to it later it will look like it did when he last saw it.The page has controls which post back and other controls are populated depending on the selections.
I'm using [Code]....
after the <@ Page directive.
What happens is that a postback gets the cached page, so no processing and it looks the same regardless of user selections. So far so good. But if I browse to another page and return by a link, the cached version is ignored and the default page is created again. This is more or less the opposite to what i want.
I attempted to use the validation callback to ensure that a postback resulted in a new version, and that worked, but it still ignored the cached page if it wasn't a postback.I realise that it will need more work to ensure each user gets their version of the page from the cache, but why bother if this doesn't work.
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]....
It's great to be able to output cache child actions, but how do I invalidate that cache?
I've been trying to use [Code]....
I wrote a Simple Control, that implements ScriptControl. This is holder for JQuery framework:
/// <summary>
/// Generic control with client behavior handled via jQuery
/// </summary>
[code]...
I create a menu control in a user contol, named as RightUserrControl.ascx.
and i kept this RightUserrControl.ascx in nearly in 200 pages.
every thing is working fine , but when ever i am going to any page the page loading is very slow, nearly each page is taking 1 minute to load.
set caching for the user control, if this is the case , do i need to declare output cache in all 200 pages or is there any alternative way to resolve this issue.
I have set the output cache for 5 pages(5 minutes)
I want to clear all these pages from cache on some nutton click
Is it possible to programmatically cache an image using VB code behind? If so, can someone lead me in the right direction?
View 14 Repliesi have 2 questions about output cache:1.is it just me , or does it seems that it is used only after the second time that the user reaches the webpage? if so, why, and how can i tweak it to my needs? my guess is that it wouldn't be logical to cache every time a user reach a webpage, but only when it happens enough times.2.i know that i can use "varybyparam" for using the output cache when the parameter doesn't change , but it seems that it would use the output cache even if there is no parameter , or if the specified paramter is not there. is there a way to overcome this?3.an old question that somehow marked as "answered" , yet i didn't solve : suppose i created a user control and i gave it values through the CTOR via the aspx file . is it possible to show the values from within the split/design mode? remember that i've talking about ASP.NET and not simply C# winforms . i write this because this question was on :[URL]and the answer that i got was for C# and winforms . i've tried to do the same for ASP.NET , but i've failed.
View 6 RepliesI need to get a UserControl VirtualPath programmatically. How can I do it?
For example, MyControl.ascx placed in Controls folder, so the result should be "~/Controls/MyControl.ascx".