i wrote a little sh*tcode that loads data from one accounting program in xml format, parses it and adds it to the database, but there is one big problem: the data is displayed on the page itself in CRM, you need to reload the page 2 times, when you first restart the page, the system turns to the cache, and when the second update actually goes to the database, I need somehow using php or js
make it so that it does not access the cache, but access the database
P.S. Version vTigerCRM 7.1 module Products
There are three solution, A) Make dynamic content in your code B) Clear Smarty Cache in your code C) Disable caching in vTiger
If option A works, it is most effective
one is to put a little footer or header in your code that changes the content to let smarty clear cache itself( for example put Date() or a number.
Second solution is to look for SMARTY to clear cache:
// clear the entire cache
$smarty->clearAllCache();
// clears all files over one hour old
$smarty->clearAllCache(3600);
Third
Look for PS_SMARTY_CACHE under Table prefix_configuration and set it to 0
Related
I have a ecommerce store website running with WordPress. I'd like to include a section with a -random custormer's product review, so that every time someone access the page, there will be a different comment there.
I'm not used to PHP, but I managed to create a shortcode which takes a random comment and returns the proper HTML. It is working fine (in eddition mode, every time I insert the shortcode a different comment appears).
My issue is that when I leave the page and return, the previous one is still there. I believe that it is being caused by cache, but I wouldn't like to disable the cache for the whole page.
How you I force the shortcode run again (I don't know if it is the right way to explain) and make sure that at every access, a different comment appears?
One solution I thought is to have JS code which would do preaty much the same thing my PHP code does, using Woocommerce API to get the data. But I'm wondering if there is a simpler solution to do that, like forcing the specific section not being cached or re-run the shortcode.
Thanks!
JS can't do what PHP does here: at most it can create an AJAX-call to the backend that then runs a query for a random comment and returns it. You need to render it thereafter. It's fairly standard, but overkill for your case.
Instead, you're going to want to check whether your caching mechanism supports ESI or something else that excluded parts of your code from being cached.
I recently have been using snippets to power a "server status" page for my MinecraftServers, and it was working fine for quite a while, however now for some reason the php code is not updating! (It became very clear when our servers went down, and sadly the server status snippets were not updating, and quite a few of our users were getting confused!)
If I could receive any help, that would be awesome-
Problem:
Php Snippets are not updating (Not even after 24 hours)
Desired Result:
Is there a way to make it update every 2-3 minutes when being used, however if no one goes to the page, not update it at all..?
Snippet Code: on
PasteBin
MODx Version - Revolution 2.2.6-pl
This is most likely due to caching.
Caching in Modx means that the system creates an individual file for each resource in your site. These files are built up by all the snippets, chunks and placeholders you may have in your template and elements being parsed.
If you chose to cache these snippets or chunks, Modx will not call the code again, but just output the content that was generated the very first time the cache was created.
These are cached:
[[mySnippet]]
[[$myChunk]]
These are uncached:
[[!mySnippet]]
[[!$myChunk]]
Please note that you want to use as much caching as possible, but the snippet you are describing (different output without removing the cache) would require uncached tags.
I've got a simple caching system that works like this:
1. Editor goes to the admin panel,
2. Enters the data,
3. The data is saved to MySQL (for good measure) and put in the HTML template.
The template itself is a part of my page where the article is presented (its like <article>...</article>). Saved in HTML as {id}.html
When user enters the page /articles/22/ I just include() the corresponding HTML page to the main template. Super simple.
But it's a little primitive IMO. And I started to wonder wouldn't it be better to store JSON with fields like title, content, tags and stuff and then parse this with PHP and put to template. It gives me a few benefits (like the possibility to put the data in other places in the template), but my first priority is speed.
So - my question would be: would it be noticeable slower to get JSON (pre-saved in text files), parse it with PHP and put into template than including pre-saved HTML file. I know there is nothing to wonder here if we talk about 100 request in the same time, but what if we talk about more? Or maybe my approach is not mature at all and I should stick to popular "user gets to the page, you check how long ago the cache file was created, you include it or get from SQL if it expired"? I don't like that. I just don't think there is any reason user should be involved in creating the cache files. The only time they change is when the editor makes some changes, so let him be the one who creates cache files.
Using read through caching will get you a long way. Basically, if an object (could be rendered HTML, json or whatever works in your flow), does not exist in the cache, you would read through to the database to build it, once built, you would store it in the cache.
If changes were made to the object, you could delete the cache and it would be rebuilt the next time it is requested.
As for a cache, you would probably want to use something like memcached, although apc could work pretty well too.
I'm attempting to write a PHP snippet that will rebuild the cached output for all pages and displays in a specific view. I have a separate process currently clearing out the caches, but then each paged output of my view has to be physically viewed in order to have the contents stored in the cache tables.
Can someone point me in the right direction? I've found the following contrib functions, but they don't seem to be what I'm looking for:
views_cache_set()
views_cache_get()
Any help would be greatly appreciated. Thanks!
If you are only dealing with cache inside of a standard view and want your displayed information to be not only current but pre cached before the first hit (and right after a flush), you can use what my partner and I are doing for our project.
We are using Views Content Cache which is very helpful for flushing the caches set inside of views to keep the information as current as possible.
Our solution is to use views_get_view_result() to invoke the view. We use
views_get_view_result('employee_master');
drupal_goto('');
You can put this code in a snippet or a function in your custom module (not sure about the .tpl files) and make rules or code to execute it.
Problem:
I've a website which has 50k+ pages and most of them are only updated once on the creation time, I am building a caching for these pages as they do not need any frequent changes on the content. But I'm confuse about few things.
If I cache whole page, how do i preserve User Login/Logout status in sidebar
How do I cache the meta tags for the page as main caching is done in the middle of page as this is most expensive part as far processing is concerned.
Take a look at the Cache_Lite PEAR module.
For your first point - you can make the login status sidebar load via AJAX, if you want to cache the rest of the page. Since the result of the AJAX request is separate (and presumably, not cached), it will update properly.
Assuming you're actually sending the meta tags as part of the page content, you might want to wait to actually write anything to the output stream until after all of your processing is done, so that you're free to compute things in any order, even if they come earlier or later in the actual page HTML content.
Obviously I don't have specific information regarding your setup, but a common tactic is to simply cache the database result/page specific content in Memcached. If Memcached isn't an option for you, you could create a writable directory on your server and just cache the page specific content there. So, you would still be generating the user specific content on each request, but without the overhead of querying the database unnecessarily.
Apply content filters before output.
You could simply use parts in your template that are reference ids of content that should be dynamic, and replace them with a the result of a function call, on the fly.
Example:
<p>some cached content</p>
<div id="user_box"> {{USER_BOX}} </div>
<p>other cached content</p>
First, fetch your cached content, then in your code, replace {{USER_BOX}} with a function call result, and finally output the modified result.
This way, you won't need to code and perform extra AJAX requests (the more server calls the less performance).
Of course you could treat your cached content with some template engine like Twig (part of Symfony) if you're using php. That would add some extra features like conditions, etc.