In light of the recent COVID-19 pandemic - OPTASY would like to offer DRUPAL website support for any Healthcare, Government, Education and Non-Profit Organization(s) with critical crisis communication websites or organizations directly providing relief. Stay Safe and Stay Well.

Cache API in Drupal 8: How Is It Any Different from Drupal 7 Cache System?

Cache API in Drupal 8: How Is It Any Different from Drupal 7 Cache System?

by RADU SIMILEANU on May 24 2019

What makes the Cache API in Drupal 8 any better than Drupal 7's cache system? What's so revolutionary about it? Which of the old limitations does it remove? What are those new concepts and terminology that you should learn about?

And, most of all: how complex is it to set up a cache in Drupal 8 for a specific use case?

You might have already bumped into terms like “max-age”, "context cache" or "cache tags".

 

But how precisely do these new concepts, part of Drupal 8's cache system, refine and streamline the way you cache data on your website?

 

Let's try to demystify the terminology of Drupal 8's Cache API and to translate its new “fancy” terminology into... crystal-clear benefits for you:

 

1. What Is Caching More Precisely? Why Do We Cache Data?

To your “What” question I'd answer:

 

Caching is a... strategy (or layer) for storing data from your website. Or: it's a software or hardware component where you store your data. 

 

Why would you want to store your data?

 

Because this will streamline the way your website serves all future requests for that cached data.

 

And it goes without saying that reading data straight from the cache takes less time than... retrieving it from a slower data container or fully recreating the result.

In short: caching data translates into faster page load time.

2. Cache API in Drupal 8: The Automatic Cache System

A brief, yet accurate definition of cache in Drupal 8 would be:

 

Storing data that takes too long to load.

 

And if I am to detail it a bit I'd have to add that:

 

Caching can be either permanent or time-limited and that you're free to cache any type of data on your website.

 

Now, talking about Drupal 8's cache API, what everyone points out is that: it is much improved. That it's so different from the cache systems of the previous Drupal versions that... you even risk turning your website uncachable if you're not familiar with its new concepts.

 

“But how different/sophisticated can it be?” you might ask yourself.

 

Before we delve deep into details let me add just one thing:

 

We're talking about an... automated cache system. Basically, your Drupal 8 website retrieves cache data for both anonymous and logged in users with no configuration whatsoever. All by default.

 

And now, let's shed some light on all these new fancy concepts that the Cache API in Drupal 8 is based on:

 

2.1.The Cache Tags

We all do agree that “invalidating cache” is one of the most challenging tasks of any cache system.

Luckily, not anymore. At least not in Drupal 8, where you now have the concept of “cache tags” that you can use for tagging:

 

  • specific pages
  • specific page elements
  • various types of content

     

… and thus invalidate them all. Improved efficiency and high accuracy through... basic tagging.

Basically, using these cache tags you can easily identify outdated data stored in multiple cache bins and... invalidate it.

This way, you no longer run the risk of invalidating “still green” cache items, in bulk, not knowing which data to invalidate.

 

2.2. The Context Cache

Here's an all too common scenario:

 

You're faced with multiple variants of the same data; only one of them should be cached, based on a specific criterion like language, user, country, content access permission...

 

Well, how do you automate targetting the right variant to be cached? And how do you automate caching the other left variants, as well, depending on the... context.

You use “cache contexts”, that's how...

They're one of those new remarkable features that the Cache API in Drupal 8 ships with, that allow you to specify the criteria to be used to vary for the cached content on a page. By user, by language, by country, by path...

 

2.3. The Max-Age (The Cache Duration)

Maybe you don't want certain data to be forever cached. Maybe you need it stored for a certain period of time only.

In this respect, the “max-age” property in Drupal 8's cache system allows you to define that time limit. To invalidate data that will have run... out of time.

 

2.4. The Bubbleable Cache Metadata

What does this even mean “cache metadata... bubbling”?

Let's take this example: 

 

You have a parent item with its own “family” of... children items. In this context, “bubbled tags” makes it possible for the parent item in this render array to receive cacheability metadata from its children.

 

Bubble cache metadata streamlines the whole process of invalidating outdated cached data. As simple as that...

 

The END!

Is it any clearer for you now what makes the Cache API in Drupal 8 so powerful? How its new features come to remove most of the limitations that you've already faced in Drupal 7?

And how you can use them to refine and automate caching on your own Drupal 8 website?

Image by Pexels from Pixabay  

Development

We do Web development

Go to our Web development page!

Visit page!

Recommended Stories

Drupal Commerce vs. Magento - Who Wins the Battle for eCommerce?
  In 2021, it is expected that about 27.2% of the world population will shop online at least once.  A lot of potential customers out there, right? As eCommerce is becoming the new norm, digital businesses seek out ways to thrive in this competitive landscape and position themselves as leading trend-setters.  To do that, companies need to realize the power of digital transformation and how they can embrace it in order to support the modern demands of speed and accessibility that customers require today.  This starts with leveraging the right tools for building robust digital assets. One of these tools is represented by eCommerce platforms, which are getting increasingly popular for businesses that seek to deploy an eCommerce system.  Drupal Commerce and Magento are two of the leading eCommerce solutions on the market and are often seen as direct competitors in the industry.  This article provides a side-by-side comparison of these two platforms in regards to technical capabilities, development, costs, scalability, security, and mobile responsiveness. Hopefully, this information will help you narrow down your choice in order to ensure that you choose the best fit for your business needs.    Key eCommerce Capabilities Enabled by Drupal and Magento Drupal Commerce was released in 2011 and offers an open-source application framework that supports retailers in building and managing inventory, track orders, or handle payments.  Magento's initial release was in 2008. This PHP-based eCommerce site provides high levels of PayPal protocol integration and supports 12 worldwide payment gateways.  Both platforms offer, through native features or third-party add-ons, the following benefits: Intuitive, easy-to-use user interface and control panels. No technical knowledge is required to customize and edit basic features. Full-featured CMS that supports social sharing. Business-centric structure for online stores. Native integration of inventory-driven advertising material Integration capabilities with third-party analytics, invoicing, or quoting solutions One thing to keep in mind is that neither of these eCommerce platforms is a "plug and play" solution and making the most out of their potential may require further expertise.    Headless eCommerce The headless version of Drupal Commerce has been in the spotlight in the last few years. This new initiative is an eCommerce solution that stores and delivers content without a front-end delivery layer. It's an API-driven implementation that transforms eCommerce functionality, making it available across a wide range of potential host environments.  A headless eCommerce model inclines towards a more SaaS-oriented, platform-agnostic solution that allows for better employee adoption and considerable time savings across IT departments.  When it comes to Magento, the open-source eCommerce platform, headless eCommerce is equally prioritized. Both Drupal Commerce and Magento are supporting headless models as the future of eCommerce.    Pricing Drupal eCommerce's technical cost of entry is free. However, depending on scope and scale, the costs of developing and maintaining performant and secure eCommerce servers might reach tens of thousands of dollars.  Drupal Commerce project costs are directly proportional with a business needs for specific development architecture, module integrations, custom theme styling, or particular feature integrations.  Magento's newer modules are not offered as open-source and upgrading from Magento Open Source to Magento Commerce might be challenging.  From this financial point of view, Drupal Commerce seems to be a clear winner.    Scalability Drupal Commerce has relevant capabilities of staying highly performant at scale. However, this CMS platform does not provide out-of-the-box database sharding and it can only be implemented on a third-party basis.  Drupal Commerce has lower requirements than Magento Commerce when it comes to the web server—the minimum required RAM for PHP is 64 MB and production systems usually require 128 or 256 MB.  Drupal Commerce-based implementation splits the eCommerce experience across three related Drupal domains. As a result, scaling is better, bottlenecks are eliminated, and the content and purchasing experiences are efficiently separated.  On the other hand, Magento's cloud hosting solves a large number of scalability issues, although at a higher price. The minimum RAM requirement of 2 GB will probably not scale well and distributed networks or caching may need to be deployed with greater care to keep up with the heavy load.    Security Drupal is proven to be the most secure CMS and Magento's infection rate is much higher than Drupal's. From the point of view of security, Drupal Commerce is a winner for businesses that want to prioritize secure platforms.  Source: Sucuri.net   Mobile Responsiveness As most websites transition to a mobile-first approach, eCommerce platforms that prioritize mobile responsiveness are a must.  Fortunately, both Magento Commerce and Drupal Commerce provide robust mobile capabilities to satisfy the need for accessibility and performance.  Drupal Commerce's themes allow building a fully responsive design for eCommerce websites and offer screen flexibility for creating versatile experiences. The most popular themes like Corolla or eStore provide: Multi-level responsive header menus Custom layouts and color options Box shadow and background textures Custom field additions Magento Commerce is close to Drupal when it comes to mobile optimization capabilities. Its responsive web design features help users create optimal viewing experiences for multiple devices. Magento Blank or Luma are out-of-the-box themes that deliver a fully responsive design.   Who's the winner for eCommerce? While both Drupal Commerce and Magento Commerce are reliable options for a digital company that wants to thrive in the eCommerce market, every business has its own unique needs and requirements. Choosing the software that best supports these needs is a process that involves a lot of research and planning.  If you want to speed up this process and ensure that you reach the right decision, don't hesitate to contact Optasy for professional advice and support.  Discover which platform is most suited to provide a robust eCommerce experience for you and your customers.  Photo credit: Mark Konig on Unsplash.   ... Read more
Raluca Olariu / Apr 06'2021
Drupal DevOps Best Practices for 2021
  Today, businesses interact with their customers in many forms of digital services on all kinds of devices. As the digital world is more and more present in our lives, delivering streamlined experiences at the tip of your customers' fingers is the key to success.  A vital role in delivering rapid, accessible IT services is played by DevOps, a set of practices that brings software development and IT operations together. And when it comes to Drupal web development, DevOps represents a valuable instrument that can maximize the potential of Drupal-delivered projects.    How does DevOps work and what benefits does a DevOps model deliver? DevOps, the culture that encompasses most digital businesses today, uses automation and advanced tech stacks to add a new layer of velocity to a company's infrastructure. “DevOps represents a change in IT culture, focusing on rapid IT service delivery through the adoption of agile, lean practices in the context of a system-oriented approach. DevOps emphasizes people (and culture) and seeks to improve collaboration between operations and development teams. DevOps implementations utilize technology — especially automation tools that can leverage an increasingly programmable and dynamic infrastructure from a life cycle perspective”. - Gartner, Inc. Businesses that incorporate a DevOps model into their workflows see benefits like:   Scalability. Fundamental processes like infrastructure and development are operated at scale, which allows for a more efficient approach to developing, testing, and producing environments in a repeatable and streamlined way. Faster and more reliable delivery. The modern customer's need for speed is real, and DevOps can support organizations in their quest to speeding up feature releases, bug fixes, and other types of upgrades. Continuous integration and delivery are two critical practices that can automate the release process. High velocity. Adopting an efficient DevOps model allows professionals to build digital innovations faster and keep up with the trends imposed by ever-changing markets. Security. When adopting DevOps, you don't have to compromise on safety as DevOps models provide automated compliance policies and configuration management mechanisms.   DevOps best practices To make the most out of DevOps, there are some key practices to follow when implementing your model:   Leverage microservices architecture, which allows breaking down large systems into more specific, independent projects. As a result, developers and architects have more flexibility over managing these projects, and applications are more pliable and allow faster innovation. Install minor updates on a regular basis to solve issues and fix bugs quicker. The DevOps model aids companies in deploying updates more often and constantly optimizing their ongoing processes. Use continuous integration and continuous delivery to overcome operational challenges in complex development workflows.  Don't forget about infrastructure as a code, as automating your infrastructure provides better computing resources and higher responsiveness to possible alterations.    DevOps for Drupal development Implementing a DevOps model into your Drupal development workflow will not only accelerate your development cycle and delivery but will also contribute to better user experiences and business outcomes.  As more companies are adopting DevOps models (according to a recent report, 60% of businesses are using or are considering DevOps for their organization), it is expected that DevOps will gradually become even more essential for any digital business. With this growth will come better opportunities for building future-ready Drupal deployments and web experiences suited for the modern customer’s complex needs.    Wrapping Up DevOps continues to grow in new industries, opening possibilities for enhancing security, product monitoring, development, and cluster computing. As it will become the new norm, DevOps will continue to integrate more departments, improve solutions and designs.  As we've seen, DevOps models can also support a Drupal development team that focuses on improving project timelines and delivery. Optasy is the right partner for fostering digital innovation and can help you create customized Drupal digital experiences.  What do you need support with?  Photo credit: PCB-Tech on Pixabay.   ... Read more
Raluca Olariu / Apr 02'2021
Tips and Tricks for Building Drupal Websites
  "A successful website does three things: It attracts the right kind of visitors It guides them to the main services or products you offer It collects contact details for future ongoing relation." - Mohamed Saad   When embarking on the quest to building successful websites, developers and website builders face various challenges such as: Crafting the site without coding Designing a good structure and making it appealing to visitors Adding specific modules and features Fixing bugs and disrupted features Connecting your brand new website to services like Google Analytics   Sailing through the rough waters of web development can be tricky at times. However, you shouldn't be discouraged. There are plenty of tools and techniques that can help you navigate website creation more skillfully, and this article will guide you through leveraging some of them. More specifically, we'll focus on Drupal web development and outline some essential tips for crafting more successful Drupal websites.  What types of websites can you create with Drupal? If your new to using this CMS, then you might be asking what Drupal can do for you. Well, Drupal is an excellent choice for almost any type of project: Personal or business websites E-commerce sites Blogs, portfolio, art, social networking websites Forums and news sites, etc. As you can see, Drupal is a versatile software that can address a wide range of needs and requirements. You only have to know how to use it to your advantage.  Keep reading and get more familiar with the world of Drupal web development.   3 Elements to Consider When You Start   1. Drupal modules. From managing user accounts to organizing basic content, Drupal offers a wide range of functional modules. It's important to remember that Drupal is known for its fantastic customization capabilities. Take advantage of the suitable modules to build personalized sites that match the needs of your visitors.    "Optimizing for impact means creating software that works for everyone. In recent years, our community has prioritized accessibility for users with disabilities, and features like lazy loading of images that help users with slower internet connections. Drupal's priority is to continue to foster diversity and inclusion within our community so all voices are represented in building an Open Web." - Dries Buytaert, founder of Drupal.   2. Web hosting allows all your site content to be seen anywhere at any time. There are some key factors to consider when choosing your web hosting service:               - loading speed: consider a host that loads faster than the current average, 850 ms.               - uptime score: look for hosts that provide high uptime scores, preferably above 99.5%.              - customer support: collaborate with a host that provides high-quality, responsive, and reliable support.              - cost: choose a host that you can afford and count on for reliability and professionalism.   3. Environment. Drupal web development is a complex process that requires focusing on functionality, appearance, or code integrity. Many elements contribute to successful side building and the environment that revolves around your Drupal project is one of them. Good environments can foster growth and are usually dependant on the following factors:                - How big the project is. This allows you to plan more efficiently, especially when dealing with multi-project environments.                  - The size of your company. This is related to the growth of your business and is underpinned by elements like discipline, culture, management, knowledge, etc.                - How skillful your team is. Having a highly experienced team that is reliable and efficient is essential when it comes to the environment.    How to maintain your Drupal website   Proper website maintenance can be challenging. Here are some aspects to pay attention to. Status report This is a feature provided by Drupal that monitors your site's health. It checks folder permissions, disruptive modules, or libraries. The Status Report feature also helps with debugging technical support issues, providing excellent support for your maintenance practices.  Cron  This is an automated task that your Drupal website runs on periodically. It performs scheduled duties like cache clearing, sending emails, or reminders, and it doesn't involve any manual intervention. This tool also performs routine maintenance for the System Module and checks for available updates.  Caching In Drupal web development, there are two modules for caching: The Internal Dynamic Page Cache Module that aims to accelerate site speed. The Internal Page Cache Module which caches pages for anonymous users in the database.  Deployment Drupal deployment allows users to move content from one Drupal site to another. More precisely, when editing your Drupal site, it is helpful to use different environments to modify or test your content without harming the live site's performance. The changes are then deployed through an automated process.    When it comes to Drupal website maintenance, it often saves a lot of resources to hire a Drupal agency to do it for you.  Optasy can help you navigate the sea of challenges that come with your Drupal project. Be it your digital strategy, web design project, or maintenance services, count on us and leave your worries behind! Photo credit: Sam Dan Truong on Unsplash.  ... Read more
Raluca Olariu / Mar 23'2021