Skip to main content

cache

Wordpress htaccess configuration

as you know that WordPress is one of the most famous CMS in the world but unforunatily it is not secure enough and we have to protect it somehow abd also we need to setup some cache configuration in the htaccess

First thing you need to do is to disable directory listing by adding this line to .htaccess

Options All -Indexes

 

the other thing you need to do is to setup the objects cache (image/css files/ js files)

this is one of the best code we can use 

 

 

Magento2 caching a blocks in a page

Magento2 Block Cache Caching plays an essential role in improving the page load time. In this article, I want to show you five blocks cache in Magento 2, or five approaches to caching, and when and how to use them. Interestingly, this article will cover both full page and block cache. Let’s explore each type of block cache together! In case, cache_lifetime of the block is set to a number greater than 0, the block is cacheable

How do I clear the cache in Magento 2 for a single product_id

the best way to do do this is using the below method


$objectManager =   \Magento\Framework\App\ObjectManager::getInstance();
$productR =      $objectManager ->create('\Magento\Catalog\Api\ProductRepositoryInterface');
$product = $productR->get('product_sku');
$product->cleanCache();
$this->_eventManager->dispatch('clean_cache_by_tags', ['object' => $product]);


you need of course to follow the DI to implement this code, I just used this quick way to make it easy to understand

 

Magento2 Refresh Cache for Single Product

Magento’s cache management system saves loaded data, configuration, instructions, images, assets, and more for increased performance loading and rapid access on the storefront. It offers increased stability on your website during heavy user load and greater customer browsing activity. Having a slow-performing website can also negatively impact your conversion

You can use this code to refresh the cache for single product