If a certain condition is met, is it possible to tell symfony not to cache the current request? I'm aware of the contextual configuration flag, but this is an action, and not a partial or component, so I don't think it applies.
Context: I'm running a multi-site CMS. Each site can have multiple domain names associated with it, but one is set as the primary. It a page request is made with the alternate domain name, it gets forwarded to the primary. But the action gets cached so when the same url is accessed, it serves the cache file instead of redirecting.
See here:
http://www.symfony-project.org/book/1_2/12-Caching#chapter_12_sub_configuring_the_cache_dynamically
You can use that approach, modifying the filter class to use whatever conditions you want to enable/disable cache.
The example in the link above disables/enables cache per module/action. You can use:
sfConfig::set('sf_cache', false);
to enable/disable it globally if preferred.
Related
I am really confused about when to use Mage::registry() and Mage session.
Can any one suggest what is diff between both on them and when to use.
The Magento registry is not persisted, as in once you are on a new page you will not see those registry variables still set. I mainly use the registry to communicate between controllers and blocks.
The session will persist, but know that there are multiple namespaces for sessions in Magento, and they will be cleared at certain times, like the checkout/session being cleared after the order is placed. It's best practice to create your own namespace for your session to avoid any conflicts like duplicate variables or clearing it at the wrong time.
As always Alan Storm has some good things to read on this topic:
http://alanstorm.com/magento_registry_singleton_tutorial
How to use Session in Magento
Use Mage::registry() when you want to access variable in the SAME page request (e.g. passing variable from controller to template)
Use session when you want to access variables across DIFFERENT page requests (e.g. navigating from one page to another)
Mage::registry() implies creation of new global variables which can be accessed anywhere within your Magento store.
Being a static function, Magento registry can be called directly without the object being instantiated as in case of dynamic functions.
Magento registry can be called like ClassName::StaticFunctionName().
while Mage::getSingleton() is just like session in PHP.
I hope I could explain my point.
I've read all over the place and I'm trying to figure out if I am understanding the way caching happens in Drupal 6. We have a site that has a real time stock ticker in it. We have Drupal caching enabled so the stock price ends up getting cached and frozen at a specific spot. I figured a way I could handle it would be to put the ticker in a block I make in a custom module and set BLOCK_NO_CACHE, but if I'm understanding this correctly, if you have site caching enabled, then the ENTIRE page gets cached including any and all blocks on it regardless of their individual cache settings. Is this correct? So am I unable to take advantage of site caching then if I have certain spots that should not cache? Does anyone know of another solution I might be able to use to have the best of both worlds? To be able to have site caching, but also have a real time stock ticker? By the way, the stock ticker is making a JSON request to the Yahoo finance API to get the quote.
You are correct, the directive BLOCK_NO_CACHE is only applicable to block level. However when page caching is enabled then Drupal will cache the entire page (which includes the block as well). But this is only applicable to anonymous users. Drupal's philosophy is that the content for anonymous users is always the same so they get served the cached page. But this is not applicable to authenticated users. Since different users might have different access to certain parts of the page (e.g. the links block will look different for an admin than a regular user).
You might want to have a look at this discussion: BLOCK_NO_CACHE not working for anonymous users
And there is a solution, which you'll stumble upon this discussion. It's this module: Ajax Blocks. Extract from the module description:
Permits to load some blocks by additional AJAX request after loading
the whole cached page when the page is viewed by anonymous user. It is
suitable for sites which are mostly static, and the page caching for
anonymous users is a great benefit, but there are some pieces of
information that have to be dynamic.
I'm using urlrewriteFilter (org.tuckey.web.filters.urlrewrite.UrlRewriteFilter) to forward pages like www.mysite.com/myname to a Struts2 action. The action is mapped up in sitemesh, and it works properly.
But now I want to keep the same URL but apply another decorator to the page, based on whether the user is logged in or not.
I'm using AppFuse-stack Struts2.
Ok - since no-one else looks like having a go.
Sitemesh selects the decorators based on the incoming url string, so to have different decorators you need different urls depending on the login status of your client. AFAIK Sitemesh uses the entire Url string so this includes parameters so you might get away with appending ?loggedIn="true" or ?loggedIn="false" and map the decorators on this. However this doesn't help with POST requests.
Another way to do it would be to create two Struts packages - one for logged in users and one for anonymous users so your actions will have different paths and then map on the path part of the Url.
I don't know how practical this might be in your scenario, but a third option maybe to have one common decorator and control the layout via seperate stylesheets which you could control via a test in your jsp.
HTH
Regards
I have a little issue with a sublayout outputting data which should differ between SSL and non-SSL requests.
To replicate if you create a sublayout and in code behind render out the URL. If you then add this sublayout to a page through the sitecore interface, eg: presentation>details etc and set caching on and set all caching variable to on. Do you publish etc so the page is now viewable (also behaves the same if your doing it directly calling the the control by sublayout control in code).
If you execute this page in non-ssl mode (http://URL) you will get a URL such as; http://URL...
Then if you execute this page in ssl mode (https://URL) your output will still be http://URL...
So does anyone know of a way to get this so we an cache both instances.
Regards,
Chris
You can use the existing VaryByParm functionality to create a VaryByUrl behaviour by programatically setting the cache key for the sublayout with the complete request url, including the scheme. I believe this would be the same process as described in Mark Ursino's response here: Customizing sublayout caching in Sitecore
As a side note, if in a multilanguage site with language prefixes be aware that using Sitecore.Context.RawUrl will give you the request url with language prefixes stripped out by the actions of the StripLanguage preProcessRequest pipeline step.
Paul
I think I see your issue -- you are outputting absolute URLs for your images, and based on whether or not SSL is used on the first request, the SSL URL of your images may or may not be included in the cached output.
My first suggestion is to disable absolute URLs, if possible. Is there a reason you need them?
My backup would be to point you at the renderingControls configuration in Web.config. If we're talking about sublayouts here, you could potentially subclass sublayout, and create a new factory for sublayout rendering. When you subclass sublayout, override its GetCacheKey method to add a flag if the request is ssl...
//if request is ssl
return base.GetCacheKey()+"#ssl";
Fair warning that I've never done this, just making an educated suggestion based on available Sitecore config and APIs.
Good luck.
I have a website which is displayed to visitors via a kiosk. People can interact with it. However, since the website is not locally hosted, and uses an internet connection - the page loads are slow.
I would like to implement some kind of lazy caching mechanism such that as and when people browse the pages - the pages and the resources referenced by the pages get cached, so that subsequent loads of the same page are instant.
I considered using HTML5 offline caching - but it requires me to specify all the resources in the manifest file, and this is not feasible for me, as the website is pretty large.
Is there any other way to implement this? Perhaps using HTTP caching headers? I would also need some way to invalidate the cache at some point to "push" the new changes to the browser...
The usual approach to handling problems like this is with HTTP caching headers, combined with smart construction of URLs for resources referenced by your pages.
The general idea is this: every resource loaded by your page (images, scripts, CSS files, etc.) should have a unique, versioned URL. For example, instead of loading /images/button.png, you'd load /images/button_v123.png and when you change that file its URL changes to /images/button_v124.png. Typically this is handled by URL rewriting over static file URLs, so that, for example, the web server knows that /images/button_v124.png should really load the /images/button.png file from the web server's file system. Creating the version numbers can be done by appending a build number, using a CRC of file contents, or many other ways.
Then you need to make sure that, wherever URLs are constructed in the parent page, they refer to the versioned URL. This obviously requires dynamic code used to construct all URLs, which can be accomplished either by adjusting the code used to generate your pages or by server-wide plugins which affect all text/html requests.
Then, you then set the Expires header for all resource requests (images, scripts, CSS files, etc.) to a date far in the future (e.g. 10 years from now). This effectively caches them forever. This means that all requests loaded by each of your pages will be always be fetched from cache; cache invalidation never happens, which is OK because when the underlying resource changes, the parent page will use a new URL to find it.
Finally, you need to figure out how you want to cache your "parent" pages. How you do this is a judgement call. You can use ETag/If-None-Match HTTP headers to check for a new version of the page every time, which will very quickly load the page from cache if the server reports that it hasn't changed. Or you can use Expires (and/or Max-Age) to reload the parent page from cache for a given period of time before checking the server.
If you want to do something even more sophisticated, you can always put a custom proxy server on the kiosk-- in that case you'd have total, centralized control over how caching is done.