This blog describes how to clear views cache while inserting, updating and deleting a node in Drupal 7. If we want to improve site performance, then views caching is one of the options.
For example, you have views which display list of records. It will update occasionally. Then we can render views data from cache rather than server if we set cache for views. We can set views cache at its settings page. Suppose you have cached views for 5 mins. Then it didn't display updated data until 5 mins even if new node is added to that views. It displays updated data only after 5 mins because the views is cached for 5 mins. In that situation, the user can't view new data in cached views. So we need to clear views cache when add , update and delete a node. So only we can see new data in views and also data is rendered from cache.
You can see the performance of views page will be increased and you can see changes in your views. Now I've hope you know how to clear views cache when insert, update and delete a node in Drupal 7.
Related articles:
Add new menu item into already created menu in Drupal 7
Add class into menu item in Drupal 7
Create menu tab programmatically in Drupal 7
Add custom fields to search api index in Drupal 7
Login using both email and username in Drupal 7
Create a page without header and footer in Drupal 7
Redirect users after login in Drupal 7
For example, you have views which display list of records. It will update occasionally. Then we can render views data from cache rather than server if we set cache for views. We can set views cache at its settings page. Suppose you have cached views for 5 mins. Then it didn't display updated data until 5 mins even if new node is added to that views. It displays updated data only after 5 mins because the views is cached for 5 mins. In that situation, the user can't view new data in cached views. So we need to clear views cache when add , update and delete a node. So only we can see new data in views and also data is rendered from cache.
Clear views cache when insert a new node in Drupal 7:
The newly added node has not been displayed in views list if the cache is applied to a views. So we need to clear views cache when insert a new node using hook_node_insert(). Lets see the code for clear views cache while inserting a node:
<?php
/**
* Imeplement hook_node_insert().
*/
function phponwebsites_node_insert($node) {
if ($node->type == 'tasks') {
//clear views cache
$viewsname = 'activity';
cache_clear_all($viewsname, 'cache_views_data', TRUE);
}
}
/**
* Imeplement hook_node_insert().
*/
function phponwebsites_node_insert($node) {
if ($node->type == 'tasks') {
//clear views cache
$viewsname = 'activity';
cache_clear_all($viewsname, 'cache_views_data', TRUE);
}
}
Clear views cache when update a node in Drupal 7:
When you tried to update a node, the updated data in that node has not been displayed in views. So we need to clear views cache when update a node using hook_node_update(). Lets see the code for clear views cache while updating a node:
<?php
/**
* Imeplement hook_node_update().
*/
function phponwebsites_node_update($node) {
if ($node->type == 'article') {
//clear views cache
$viewsname = 'articles';
cache_clear_all($viewsname, 'cache_views_data', TRUE);
}
}
/**
* Imeplement hook_node_update().
*/
function phponwebsites_node_update($node) {
if ($node->type == 'article') {
//clear views cache
$viewsname = 'articles';
cache_clear_all($viewsname, 'cache_views_data', TRUE);
}
}
Clear views cache when delete a node in Drupal 7:
After delete a node, you could see the deleted node is displayed in the views. So we need to clear views when delete a node using hook_node_delete(). Lets see the code for clear views cache while deleting a node:
<?php
/**
* Imeplement hook_node_delete().
*/
function phponwebsites_node_delete($node) {
if ($node->type == 'article') {
//clear views cache
$viewsname = 'articles';
cache_clear_all($viewsname, 'cache_views_data', TRUE);
}
}
/**
* Imeplement hook_node_delete().
*/
function phponwebsites_node_delete($node) {
if ($node->type == 'article') {
//clear views cache
$viewsname = 'articles';
cache_clear_all($viewsname, 'cache_views_data', TRUE);
}
}
You can see the performance of views page will be increased and you can see changes in your views. Now I've hope you know how to clear views cache when insert, update and delete a node in Drupal 7.
Related articles:
Add new menu item into already created menu in Drupal 7
Add class into menu item in Drupal 7
Create menu tab programmatically in Drupal 7
Add custom fields to search api index in Drupal 7
Login using both email and username in Drupal 7
Create a page without header and footer in Drupal 7
Redirect users after login in Drupal 7
So could this be described as custom version of https://www.drupal.org/project/views_content_cache? What are important differences?
ReplyDeleteViews content cache is content aware. That is it checks that the node is contained in the view. This solution checks for the content type of the node and clears the cache based on that.
ReplyDeleteNo thank you comments allowed here .. Access denied .. Strange
ReplyDeletepatents on simultaneous localization and mapping We have made extraordinary steps with regards to mechanical technology. In any case, where we've come at a stop is the absence of help to the robots with regards to finding the area.
ReplyDeletesimultaneous localization and mapping slam self driving cars
Is it true that you are encountering moderate stacking when you visit your website?view cached web pages
ReplyDeleteFoundations that are dark in shading naturally presents such countless issues most particularly with the pages lucidness. SEO Antwerpen
ReplyDeleteI just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page!
ReplyDeletedịch vụ vé máy bay tại nga
mua vé máy bay từ anh về việt nam
bay từ pháp về việt nam mấy tiếng
ve may bay tu Duc ve Viet Nam
dat ve may bay tu han quoc ve viet nam
Vé máy bay giá rẻ tu Nhat Ban ve Viet Nam
I’ve found every article I’ve read very helpful. Good one, and keep it going. seo
ReplyDeleteI'm exceptionally touchy to food. However, I am not a colossal enthusiast of doctor prescribed prescription. I have utilized charcoal various occasions to alleviate me of the "butterflies in my stomach" feeling I get frequently. tree stump removal service near me Sacramento, CA
ReplyDeleteA big thank you for your article post. Really thank you! Fantastic.
ReplyDeletehttps://twitchviral.com/
This is one awesome blog. Really thank you!
ReplyDeletehow to post reel to instagram from pc
Independent robots can play out any undertaking with exactness and high proficiency. They are robotized since they don't need any sort of control by means of people. Mechanical technology is beginning to run the world by advancements becoming on an everyday premise.patents on SLAM
ReplyDeleteI cannot thank you enough for the post. Much thanks again.
ReplyDeletepost to instagram from pc
It is the place where their consideration is engaged and where they first search for data, including insights regarding schools. best ip address tracker online
ReplyDeleteThank you for shearing post amazing this is post very useful for me.
ReplyDeleteNew Media
New Media
New Media
New Media
New Media
New Media
New Media
New Media
perde modelleri
ReplyDeletesms onay
VODAFONE MOBİL ÖDEME BOZDURMA
nft nasıl alınır
Ankara Evden Eve Nakliyat
trafik sigortası
Dedektor
https://kurma.website/
aşk kitapları
pendik lg klima servisi
ReplyDeletebeykoz toshiba klima servisi
maltepe beko klima servisi
kadıköy beko klima servisi
kartal lg klima servisi
ümraniye lg klima servisi
kartal alarko carrier klima servisi
ümraniye alarko carrier klima servisi
kartal daikin klima servisi
Good content. You write beautiful things.
ReplyDeletevbet
taksi
hacklink
vbet
mrbahis
korsan taksi
hacklink
sportsbet
sportsbet
Success Write content success. Thanks.
ReplyDeletebetturkey
betpark
canlı poker siteleri
canlı slot siteleri
kıbrıs bahis siteleri
deneme bonusu
betmatik
niğde
ReplyDeleteyalova
çeşme
mardin
ZN1
kütahya
ReplyDeletenevşehir
erzincan
adana
bartın
SCA
yurtdışı kargo
ReplyDeleteresimli magnet
instagram takipçi satın al
yurtdışı kargo
sms onay
dijital kartvizit
dijital kartvizit
https://nobetci-eczane.org/
2TUBN
salt likit
ReplyDeletesalt likit
DFU