Concrete5 v8 block cache in edit mode - concrete5

Using Concrete5 v8.4.2, I created a custom block for my site where, like the Image Slider, it displays a placeholder when in Edit Mode. When Block Cache is enabled in the Cache & Speed Settings, the public view is cached for the block and the edit mode view is no longer displayed.
The Image slider appears to get around this by using $btCacheBlockOutputForRegisteredUsers = false, but this is a high traffic site, so I really only want to disable the cached view when the page is in edit mode, not for all signed in users.
A previous question Concrete5 (5.7) - Don't cache page or current block on block error is close to what I want to achieve, but I am hoping that I can not render the cached view in Edit Mode, rather than expire the cache (on a trapped error). It would be bad for me to expire the cache, then end up caching the Edit Mode view. This question is also 18 months old and on a previous version of Concrete5, so I am hoping there is a better solution for my issue.

Rather than making the edit mode / view decision in php, you can do it in JavaScript.
In the block JavaScript, you can test CCM_EDIT_MODE and only run the other scripts and show the normal block view if it is false, or replace the markup with an edit mode marker if it is true.

Related

My website requires multiple refreshes to show new content

I am in charge of updating a large e-commerce website, tedbrownmusic.com. We hired an outside web developer to code the website, so I'm not very familiar with the back-end side of things.
My problem: The front page requires multiple manual refreshes in order for newly posted content to show up.
The front page is an ASP.NET storefront, separate from the rest of the site (which is run on Wordpress). The Wordpress site loads properly, but on the front page, I have to hit F5 a bunch of times for new stuff to show up (I am using the newest version of Chrome). In IE, it refuses to refresh at all. The cache has to expire before a user in IE can see new content.
The web developer said there was nothing he could do about it. But that doesn't seem like normal website behavior to me.
I have tried adding "no-cache" META tags to force the page to refresh every time it is visited, but it didn't work.
Any thoughts? I appreciate it.
If you are using css/js files, you can try to force browsers to load the latest CSS file by changing a version number. I think its called as css versioning.
<link rel="stylesheet" href="yourwebsitescsslocation/style.css?v=1324491378" type="text/css" />
if you change 1324491378 to some other value it will force browser to load css again rather than from cache. You can use changeset number or current timestamp as version number and make sure that it changes everytime you make changes to css.
see below article for some additional help:
http://www.codeproject.com/Articles/203288/Automatic-JS-CSS-versioning-to-update-browser-cach

Drupal 6 - Disable Views cache for specific View

I have lots of views which don't change very often, and enjoy the benefit of caching. But I have 1 view which is used to display a random quote in a block in my sidebar, which I do not want cached. Is there a way to disable caching for this particular view? Specifically, I want to see a different quote every time I refresh the page.
UPDATE: I have Caching Mode set to Normal in my site's Performance settings, and I've tried going into the View and setting Caching = None (as well as in Block settings: Caching = Do not cache), and going into the Views tools page, and selecting "Disable views data caching", and it works when I'm logged in, but as soon as I logout, the quote stays the same after refreshing.
UPDATE: I'm beginning to think that if you have enabled page caching in Drupal, then all other cache settings are ignored (i.e. View and Block caching). Can anyone confirm this?
In the Views UI under the Basic settings of a particular display you have an option called Caching make that as none. And your view won't be cached. So you get random
quote everytime. :)
EDIT : Oops how did I miss what you were telling :(
Use Cache Exclude module to disable caching on the particular page. If your random block is on many pages, you may need to dig deeper to find an alternate solutions. All the best ;)
Suggestion: Randomize on the client side. Load 'em all up into a javascript array and write a quick function to select the random quote on page load. Unless there are hundreds of possible quotes it shouldn't weigh the page down too much, & you could exclude this one little sidebar feature from consideration when working on your caching strategy.
In fact even if there are hundreds of random quotes, you could use a combination of the two approaches. Grab 50 random lines w/ your module and them let javascript pick from there. To an end user it would be nearly identical.
The block may be being cached. Did you try to http://drupal.org/project/blockcache_alter ?
You can also directly change a block's cache setting in the database with something like:
update blocks set cache=-1 where bid=<blockbid>;
Setting this cache entry to -1 means the block will not be cached.
In addition, setting cache to 1 will cache the block per role, 2 will cache the block per user, 4 will cache the block per page, and 8 will cache the block exactly once (the same for all users, pages, etc).

Is it better to cache an element in the block/view or the panel?

I am creating a panel page that will pull in blocks from a view? I want to cache these blocks. So is it better to enable caching of that element in the panel or do it where it was created in the block/view page? Or does it matter?
FYI, There are other areas of the page that are too dynamic for me to cache the entire page using other methods
Go to the top level, to get the cached version faster. In this case, that would be the panel page.
That would also cache the entire pane, instead of just caching the content of it, be it a block, a view or something else.
If you have a panel, containing a block display of a view, you're doing it wrong (probably). You should be using a content-pane display of your view for use in the panel.
That said, only the outer-most cache is used, so if you cache the panel, and cache the block inside the panel, and cache the view inside the block, only the panels-cache is actually used.

How to serve different cached versions of a page depending on a cookie in Drupal?

The task is relatively straightforward:
A Drupal website displays a list of articles with thumbnails. Some visitors would like to view it without images by clicking on a button/link and have that preference saved.
e.g. http://patterntap.com/collections/index/
The problem is all visitors are anonymous and given certain traffic, page cache is enabled.
My idea was to use some simple JavaScript to set a cookie, refresh the page and depending on the cookie values (or its presence/absence) display or hide the images.
Except Drupal serves cached pages quite early and the only quick way to modify the cached version that I could find is by hacking includes/bootstrap.inc and add a custom class to the body classes then hide the images with css.
A very wrong approach, I know. But I wonder if there is a way to save different versions of a page and serve the correct version?
Edit:
need to keep the same uri
the js to show/hide the images without reload and set the cookie is already in place
hook_boot() is not really called for cached pages, so can't do it via custom module
.htaccess mods?
Edit/solution:
In the end went with Rimian's suggestion. But it is possible to accomplish the task using our own cache.inc implementation as seen in the Mobile Tools module. Specifically, by extending cache.inc and updating settings.php to include
$conf['page_cache_fastpath'] = FALSE;
$conf['cache_inc'] = 'path/to/my/module/my_module_cache.inc';
So let me get this right. You wanna hide some images on a cached page if the user chooses to?
Why don't you write some jQuery or javascript and load that into your cached page with all the rest of the document?
Then, the client/browser would decide to run your script and hide images depending on some parameters you passed along with the request to that page or in the cookie? The script gets cached and only runs when you call it.
If you were hacking the bootstrap for something like that you'd really need to be rethinking what you were doing. Crazy! :)
Also take a look at cache_get and cache_set:
http://api.drupal.org/api/drupal/includes--cache.inc/6
I'm not sure I 100% understand what you are trying to do but here are my thoughts. One of your root problems is that you are trying to access what is essentially different content at the same uri.
If this is truly what you want to do, then Rimian's suggestion of checking out chache_get and chache_set may be worthwhile.
Personally, it seems cleaner to me to have your "with thumbnails" and "without thumbnails" be accessed via different uri's. Depending on exactly what you are wanting to accomplish, a GET variable my be an even better way to go. With either of these two options you would hide or show your thumbnails at the theme layer. Pages with different paths or get variables would get cached separately.
If you want the visitor to be able to switch views without a page reload, then jQuery and a cookie would probably suite your needs. This wouldn't require a page reload and switching back and forth would be quite simple.

Detect IE setting: check for newer versions of stored pages "never"

I understand there isn't a way to interrogate a users IE settings directly due to security reasons, but is there a way to derive this answer with some other mechanism? I would like to stop a user from using my site if the setting "Check for newer versions of stored pages" is set to "Never". Any suggestions?
Is there a way I could test for this using javascript? An example of what I am trying to accomplish is this: While it is not possible to check IE settings to see if you are running a popup blocker, that is a way to "test" for a popup blocker via javascript. I am looking for something similiar but for the cache setting, not the popup blocker.
Append something to the querystring that is unlikely to have been used before (a datestring, a random number).
That will make IE 6 request the page again, as far as IE is concerned, its another page.
So if you have http://somepage.com/dontcachethis.html you'd replace this with something like http://somepage.com/dontcachethis.html?please=23143425 where you asign please a random number.
Add the following to your web pages:
meta http-equiv="Pragma" content="no-cache"
meta http-equiv="Expires" content="0"
This forces the user's browser to reload the pages every time, regardless of the browser's cache settings.
I've not implemented this yet, but this is my plan:
Write out a date onto the page that is on an attribute of some HTML element (this should be written server side...writing it with javascript will defeat the purpose)
Using javascript, load in the date. If it is over a certain amount of time, I can assume they have not loaded a fresh copy of the page. If that is the case, continue on...
If I've detected that they have an old version of a page, I could do a couple things:
I could warn them of this problem. I could show them the setting that they need to change.
I could redirect them to the same page but add something onto the querystring so it looks like a different page to the browser. If I do this, I would add something in my javascript that knows about this potential redirect loop.

Resources