A template stored in a database as described here, then edited and persisted cannot be rendered for review without clearing the cache, even in dev mode. Once the cache is cleared, the template remains fixed until cache is cleared again.
Presumably there is a method somewhere that allows such an edited template to be available immediately without having to clear the cache?
There is two options
1) disable the cache on twig:
twig:
cache: false
2) remove the cached file when you updated the view on the database:
$fileCache = $this->container->get('twig')->getCacheFilename('YourBundle:Default:index.html.twig');
if (is_file($fileCache)) {
#unlink($fileCache);
}
Let me know if that works for you.
Related
I am trying to upgrade the old project(based on storefront for Sitecore 8.0) to version Sitecore 8.1(latest one at the moment).
During this process I faced with a problem when I see the same products for all categories. So, for example, I select a category first time and see correct products. After that I choose any other category, but still see the same products(from the first category).
These data are returned by ProductList rendering(a controller rendering) and it is not run after the first call anymore(tried to reach corresponding action in a CatalogController in debug mode).
If we clear all caches(..sitecore/admin/cache.aspx) - then it works again, but only first time.
I understand that I can't disable caching for the whole site, I need to do it for this generic page(with "*" in item name) where the commerce data are shown - so for all categories and product pages. I checked this rendering in design mode and can see that all checkboxes related to cache are unchecked at the moment. Don't know what I have missed.
Thank you in advance for the help.
I believe you have caching enabled on control/sublayout defintion level which will cause to cache that rendering on every page on the site, a while ago i was able to come up with a solution to disable caching for a specific rendering/sublayout on specific pages, while keeping it caching on other pages.
I basically created a new rendering parameter template with checkbox "Cancel Cache Settings", then in my rendering definition item, I set the parameter template to the new template, if your site runs on Sitecore MVC, do the following:
Create a class called 'SetCacheability'
namespace Sitecore.SharedResources.Pipelines.Rendering
{
public class SetCacheability : Sitecore.Mvc.Pipelines.Response.RenderRendering.SetCacheability
{
protected override bool IsCacheable(Sitecore.Mvc.Presentation.Rendering rendering, Sitecore.Mvc.Pipelines.Response.RenderRendering.RenderRenderingArgs args)
{
if (!String.IsNullOrEmpty(rendering.Parameters["Cancel Cache Settings"])
&& rendering.Parameters["Cancel Cache Settings"] == "1")
{
return false;
}
return base.IsCacheable(rendering, args);
}
}
}
Create the patch config file in your include folder:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<mvc.renderRendering>
<processor patch:instead="processor[#type='Sitecore.Mvc.Pipelines.Response.RenderRendering.SetCacheability, Sitecore.Mvc']"
type="Sitecore.SharedResources.Pipelines.Rendering.SetCacheability, [YOUR ASSEMBLY NAME]"/>
</mvc.renderRendering>
</pipelines>
</sitecore>
</configuration>
Here is the blog i wrote on this: http://www.sitecorecoding.com/2014/09/disabling-caching-for-rendering-on-some.html
Hope this helps
The caching settings you've disabled are located in the presentation details on the control level:
Additionally, you should ensure that caching is disabled on your sublayout (or rendering) definition (under /sitecore/Layout/Sublayouts):
My backend always responds with all available data and it took a considerably amount of time. So I'm reloading store periodically and I plan to use peekAll() and peekRecord().
My code is:
model: function() {
return Ember.RSVP.hash({
'clusters': this.store.peekAll('cluster'),
'single': this.store.peekRecord('cluster', 'cluster::My')
});
When code is executed, at first I can see that both of these items do not contain content. After few seconds data are loaded to store and I can see content 'clusters' on template as expected. But 'single' is still completely without content ({{model.single}} does not return nothing in template). But when I have a button with action:
alert(this.store.peekRecord('cluster', 'cluster::My'));
I can see that the record was found. Records are also available via Ember Inspector. What am I doing wrong that only peekAll() works in model for me.
The semantics of both methods are:
store.peekAll returns a live array that is updated as the store is updated.
store.peekRecord returns the corresponding object in the current cache, or null, and it does not update.
So the behaviour you're observing is the expected one. If you want to use the peek methods, my advise is to make sure that the initial request has finished loading before fetching any data from the store.
I believe Sitecore is caching an item's workflow value and I need to be able to clear it.
The scenario is that I issue an ajax request to determine whether a specific item exists and if it does exist retrieve its Workflow field value. The user fills out a form and they have the options to Save or Submit that form; when they submit the form it enters a Workflow state. However, even if I switch browsers the LoiHasNoWorkflow keeps the previous value unless I publish again. I have a method to clear some caches but I'm not sure which might be actually caching the field.
public static bool ClearCache()
{
foreach (DictionaryEntry entry in HttpContext.Current.Cache)
{
HttpContext.Current.Cache.Remove((string)entry.Key);
}
Context.Database.Engines.TemplateEngine.Reset();
Context.ClientData.RemoveAll();
CacheManager.ClearAllCaches();
return true;
}
public bool LoiHasNoWorkflow => CBUtility.ClearCache() && string.IsNullOrEmpty(loi?.Fields["__Workflow"].Value);
How can I determine why the item's __Workflow value won't clear? I can even delete the item through Sitecore UI, refresh the page, and issue the same request but get the value when the item did exist.
Actually the issue turned out to be not related to the cache but my own mistake. My loi object was a static variable within that class and so it wasn't getting cleared out on every page refresh. Here is the SO deeper explanation that led me to this realization. Actually learned a bit more about how static variables.
Lifetime of ASP.NET Static Variable
Basically, the hash on the cache busting file is not updating.
class S3PipelineStorage(PipelineMixin, CachedFilesMixin, S3BotoStorage):
pass
PIPELINE_JS = {
'main.js': {
'output_filename': 'js/main.min.js',
'source_filenames': [
'js/external/underscore.js',
'js/external/backbone-1.0.0.js',
'js/external/bootstrap-2.2.0.min.js',
]
}
}
When I first ran the collectstatic command, it properly created a cache busting file named "main.min.d25bdd71759d.js
Now when I run the command, however, it is failing to overwrite that cached file (and update the hash) during the post process phase.
It keeps updating "main.min.js", such that main.min.js is current with my filesystem. A new cached file, however is not created. It keeps the same old hash even though the underlying main.min.js file has changed.
When I manually delete the cached file on AWS, I get the following message from running collectstatic with verbosity set to 3:
Post-processed 'js/main.min.js' as 'js/main.min.d25bdd71759d.js
settings.DEBUG is set to False
Why won't the hash update?
Try using the manifest storage instead:
class S3PipelineManifestStorage(PipelineMixin, ManifestFilesMixin, S3BotoStorage):
pass
According to the django docs here https://docs.djangoproject.com/en/1.11/ref/contrib/staticfiles/#cachedstaticfilesstorage it's not recommended to use CachedStaticFilesStorage.
Your files names for your static files are probably getting cached. So use the manifest one.
CachedStaticFilesStorage isn’t recommended – in almost all cases ManifestStaticFilesStorage is a better choice. There are several performance penalties when using CachedStaticFilesStorage since a cache miss requires hashing files at runtime. Remote file storage require several round-trips to hash a file on a cache miss, as several file accesses are required to ensure that the file hash is correct in the case of nested file paths.
Note this is also documented at django-pipelines http://django-pipeline.readthedocs.io/en/latest/storages.html#using-with-other-storages
After changing an association and then changing it back (a couple of times), the association is lost.
var newCar = MyApp.CarModel.find('hummer');
MyApp.Person.find('wycats').set('car', newCar);
var oldCar = MyApp.CarModel.find('toyota');
MyApp.Person.find('wycats').set('car', oldCar);
Not very easy to explain, but very easy to see in this jsfiddle:
http://jsfiddle.net/Vz3E6/2/
Click the buttons in this order and you will see that the association is lost: 1, 2, 1, 2
I am using ember-latest and ember-data-latest.
EDIT: I have created a copy of this question as an issue on the ember-data issue tracker here: #465
This is a bug in the latest version of Ember Data. When Ember Data detects that a change to a child will effectively undo an earlier, as-yet-uncommitted change, it rolls back the parents, but fails to actually roll back the child and (because of some messy internal details) winds up setting it to null instead.
We have an open pull request introducing hasOne associations which happens to fix it with this line, as proven by this test.