Russian-Doll Caching in Laravel

0
Language

Level

Beginner

Access

Paid

Certificate

Paid

Popularized in the Rails world, Russian Doll caching is an interesting approach, where you create nested fragment caches for your view logic. If you then link the keys for each of these cached items to the model’s “updated at” timestamp, what you get is easy caching for your view logic, and automatic cachebusting whenever the model is updated.

In this series, we’ll build a custom package from scratch to offer this very functionality.

Add your review

Overview and Homestead Setup

Let’s begin by learning what Russian Doll caching actually is, and then moving on to the initial project setup, where we install both Laravel and Homestead for the project.

We Need Something to Cache

Before we can starting building our caching system, we first need some sample data to cache. So let’s use this idea of an index card and notes. In this lesson, we’ll build up the necessary route, models, and migrations.

Russian Doll Caching

Now that we have all the setup out of the way, let’s write a custom Blade directive so that we may begin implementing our Russian Doll caching mechanism.

Create a Package

At this point, our experiment is working. However, for any new project, we’d have to copy all these files over. Gross. Let’s instead begin creating a reusable package, which we can then pull in through Composer.

Refactoring and Testing

Before we make this package available on Packagist.org, let’s do some refactoring and write some tests. As you’ll find, these tests might drive us toward a slightly different design. Let’s see!

How to Use Local Packages in Laravel

So far, we’ve been building our package in isolation. But, of course, we need to try this out within the context of an actual Laravel project. How exactly do we do that? Well, as it turns out, we can install local repositories with Composer quite easily. In this lesson, we’ll do our final tweaks in preparation for Packagist.org.

Registering With Packagist

The initial version of our package is ready to release. Naturally, there are a number of improvements we can make, but what we have so far is good enough for a 0.1.0 release. So let’s register our package with Packagist.org.

User Reviews

0.0 out of 5
0
0
0
0
0
Write a review

There are no reviews yet.

Be the first to review “Russian-Doll Caching in Laravel”

×

    Your Email (required)

    Report this page
    Russian-Doll Caching in Laravel
    Russian-Doll Caching in Laravel
    LiveTalent.org
    Logo
    LiveTalent.org
    Privacy Overview

    This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.