Optimizing Bagisto E-commerce: A Deep Dive into Full Page Cache Implementation

Updated 7 December 2023

Bagisto latest version 2.0 introduces Full Page Cache support to deliver lightning-fast page loading, improved SEO, scalability, and reduced server load for enhanced eCommerce performance. Here in this article, We are going to explain the full-page cache in bagisto step by step.

Full-Page Cache is like a turbocharger for your online store. It’s a sophisticated technology that allows us to store entire web pages in a high-speed cache.

When your customer visits the website, instead of generating each page from scratch, we can instantly serve you a pre-built, fully rendered version of the page. This means faster load times, smoother navigation, and an overall snappier shopping experience.

Understanding Full Page Cache: Full Page Cache is a mechanism that stores entire HTML pages in the cache. When a request is made for the same page, the cache seamlessly serves the page without the need for re-executing server-side logic. This process allows for faster page load times as the cache provides a quick and efficient way to serve the requested page without the need to run the server-side logic again. This reduces the need for database queries, template rendering, and other resource-intensive tasks, resulting in faster page load times.

We used the Spatie Laravel Responsecache Package in Bagisto2.0

1. How to Enable Full Page Cache In Bagisto
a) Go to the .env Configuration file
b) set RESPONSE_CACHE_ENABLED=true

2. How to set Cache duration and other Configuration
Navigate to this path to adjust cache duration and explore other configuration settings for Full Page Cache in Bagisto. Here, you’ll find all the configurations related to Full Page Cache.
a) config/responsecache.php.

3. Comparison of Bagisto 2.0 With FPC and without FPC

A) Home Page

Without FPC

As you can see in the below image the loading page is around 81.58 milliseconds.

With FPC

In the below image, you can see the page load time decreased by around  66.16 milliseconds.

B) Category Page

Without FPC

As you can see in the below image the loading page is around 132 milliseconds.

With FPC

In the below image, you can see the page load time decreased by around 62.78 milliseconds.

Bagisto 2.0, the latest version of our e-commerce platform, brings significant enhancements to improve overall performance and user experience.

4. Supported Cache Drivers

Bagisto supports all cache drivers supported by Laravel, providing unparalleled flexibility in optimising your e-commerce application’s performance. for example…

5. Clearing  Response Cache with Artisan Commands:

To effortlessly clear your application’s response cache in Bagisto, utilize the following command:

6. Cache invalidation

Here are some common techniques for cache invalidation in Laravel:

  1. Time-Based Invalidation: Time-Based Invalidation optimizes cache maintenance by storing data for a predefined duration. Once this time period elapses, the cached information is automatically removed, prompting the system to fetch and update with the latest data. This strategy ensures that the cache consistently reflects the most current information within the specified time frame.
  2. Manual Invalidation: Developers can manually clear the cache when they know that the cached data is outdated. This can be done through a manual process or by using specific commands or tools.
  3. Event-Based Invalidation: Event-Based Invalidation enhances cache management by clearing the cache in response to specific events, like database updates, file modifications, or other data changes. This proactive approach ensures that the cache is always up-to-date, aligning with the latest data modifications.

We created some events to automatically invalidate the cache, ensuring that we consistently retrieved updated data.

1. Create the EventServiceProvider class: We create an EventServiceProvider in the src/Providers directory. This file contains the code for the event service provider, which can be used to register events and their listeners. To register an event and its listener, you can add them to the $listen array in the EventServiceProvider class.

2. Register the service in the FPC service provider: In the FPCServiceProvider.php file, locate the boot()  method. Here you can see we add EventServiceProvider within the boot() method.

For instance, in the realm of event-based cache management, consider the event ‘customer.review.update.after’ triggered from the review controller upon a review update. This seamless integration guarantees swift cache clearance or update, maintaining synchronization with the latest review modifications.

In the directory “packages/Webkul/FPC/src/Listeners,” you can find the afterUpdate() method. This method clears the cache using the forget() method when a review is updated.

Thank you for reading this tutorial. We hope you found it helpful. If you have any questions or encounter any issues, please feel free to leave a comment below.

Feel free to hire Laravel developer to build your custom solutions on Laravel. For exploring the available extensions for Bagisto, you can check out bagisto.com.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project




    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home