Clearing and Locating Cache0:32
sandbox of space inside that application cache. It's this area that effectively becomes a database with indexes and maps to different files and relationships and everything. So I'm going to show you how all that comes together so that you can understand it and hopefully take advantage of it to the fullest. Let's go. First, let's clear everything. Be php artisan cache:clear. Let's wipe the application cache entirely and then go to storage/framework/cache. This is where we're going to live right here.
Let's wipe the application cache entirely and then go to storage/framework/cache. This is where we're going to live right here. Now since the cache is empty, there's really nothing in here. Just some .gitignore files making sure that the directories still exist. So let's get some data in here so we can take a look at it. Let's go to the control panel and just refresh. It should be about the minimum amount of data we'll request at any one time. Back to our editor. We can see Laravel has some stuff here and then here's the stash. It's broken out into three subdirectories.
Stash Directory Structure1:25
We can see Laravel has some stuff here and then here's the stash. It's broken out into three subdirectories. We've got indexes, which is where we store maps between any key and the file that it belongs in, items where the actual data is installed, and then keys, which allows us to make sure that we don't have any duplicate IDs. So as you can see right here inside items, we have asset containers and users. That's because Statamic will only request the data that it absolutely needs for that request. This is basically lazy loading. So since I have an active user session, it's requested data on our user, like
This is basically lazy loading. So since I have an active User session, it's requested data on our user, like avatar, and that kind of thing. If we go to the collection section, now we'll see that we have collections, entries, taxonomies. Inside that, we have news and pages. Inside that, we have all the different entries inside of our collection. The file name of each file in here is the ID. Okay. Now, if we were to pop open this file, open it anyway, this is serialized data, which
Inspecting Serialized Items2:23
Okay. Now, if we were to pop open this file, open it anyway, this is serialized data, which is pretty hard to look at and explore. So I'm going to use TinkerWell to show you what's actually going on here. Let's take this first news entry, for example. If we pull that out of the stash, we can see that we have all that entry's data. So we don't have to loop through anything to go get this data. Statimate can just dive right into this cache file because we know the ID and what collection it belongs in. Now, if we look at the indexes, the indexes allow us to figure out faster and quicker.
Understanding Cache Indexes2:52
collection it belongs in. Now, if we look at the indexes, the indexes allow us to figure out faster and quicker ways to get to the files when needed. Let's look at the entries news path index. This maps the ID of an entry to the actual file path that you'll find the data in. So for example, if we know we're requesting this ID for data, here's where it's going to go get it. It's going to augment and compile that and then send it and then cache it here in the items directory. Now, if we look at the date, for example, this bit of the cache is empty.
Warming and Clearing Cache4:29
delete or store things. So this allows us to know. So we know we need to do cache forget path, cache forget site, and so on when it's time to blow the cache away. If we want to warm the entire cache, cache everything that Statimate might need, whether it needs it for that particular request or not, you can run php artisan cache:warm. This is going to make sure that everything is loaded. And now you can see all of the indexes that we have. So slugs and tags, title, etc, anything that you might filter or sort based on we have an index for.
So slugs and tags, title, etc., anything that you might filter or sort based on we have an index for. php artisan cache:clear, which includes the stash. The stash can be cleared on its own with the stash clear command. Maybe notice this timing file here. If we head back to our control panel, go to the utilities area. We have a cache manager that shows some interesting information about your stash, the number of records that are in it, the amount of file size that it's actually taking up, and build time, which is how long it takes to build the entire stash end to end. So this was only going to be measuring like a full stash warm, not the incremental builds.
Moving Cache to Redis5:31
time, which is how long it takes to build the entire stash end to end. So this was only going to be measuring like a full stash warm, not the incremental builds. So you can clear that right here, you can warm it again, but this is pretty useful. If you find yourself with 10s of 1000s of records in the stash, it might be time to look at using the database driver or perhaps Redis. Since the stash is inside Laravel's application cache, all you need to do is move that application cache to another driver. So let's switch over to Redis and I'll show you what I mean. We composer require redis or predis. I actually don't know what the right way to say it is.
We compose a require to Redis or Predis. I actually don't know what the right way to say it is. Then we head to our .env file and we switch our cache driver to Redis. Now we can open TablePlus. Look for DB1, the only site I've got running right now, and here's that whole stash stored right here. I hope it's becoming clear to you throughout this course just how flexible Statamic is in terms of your data. If it's your data, you should have it stored however you want. I really hope this course has been useful for you.
