Spring Boot Fundamentals: Improving Performance by Implementing Caching | ChargeAhead LLC | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Spring Boot Fundamentals: Improving Performance by Implementing Caching

teacher avatar ChargeAhead LLC, Technologist

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

10 Lessons (31m)
    • 1. Course Overview

    • 2. Roadmap

    • 3. Audience

    • 4. Prerequisites

    • 5. Tools

    • 6. Demo: App overview

    • 7. Demo: Adding caching to our application

    • 8. Demo: Conditional caching

    • 9. Demo: Switching the cache provider to Redis

    • 10. Summary

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

Caching is a useful strategy to improve your app’s performance. In this course we will demonstrate the caching support Spring Boot provides. With just a dependency and a few annotations you can devise an effective caching strategy for your application. 

We will add the spring boot starter cache dependency to our application  to quickly add basic caching dependencies. Spring Boot will autoconfigure the cache manager for you.

Next we will devise a caching strategy for our crud services using various caching annotations like Cacheable, CachePut, CacheEvict etc. This will ensure that the cache stays current and any change to the underlying data makes Spring Boot reload the data in cache. 

We will also look at conditional caching.

Next we will switch our cache provider to be Redis and see that all the change we need to do to our app is essentially put the redis dependency in our pom and add a few properties. Spring Boot makes it very simple for us.

Meet Your Teacher

Teacher Profile Image

ChargeAhead LLC



Class Ratings

Expectations Met?
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Course Overview: cashing is a useful strategy to improve your ABS performance. In this course, we will demonstrate the cashing support Springwood provides, but just a dependency and a few annotations. You can devise an effective cashing strategy for their application. Hello, My name is Pankaj Jane. And welcome to the scores on spring Good fundamentals. Improving performance by implementing cashing in this course Well, first, talk about hold with the right audience for the scores. Prerequisites for them to get the most out of the scores and tools you need to follow along . You will. Aren't the spring boot started cash dependency toe our application to quickly add basic cash in support? Spring Boot Lord, to configure the cash manager for you next Ever devised a cashing strategy for ever occurred services using various cashing in notations like Ashley Able cash, port cash, evict, etcetera. This will ensure that the cash stays current and any change to the underlying data makes spring boot reload the did in the cash. We will also look at conditional cashing. Next, we will switch our cash provider to be read this and see that all the change we need to do toe app is essentially to put the reddest dependency in our palm file and not a few properties. Springboard makes it very simple for us. All right, this would be an exciting course. Let's get started. 2. Roadmap: I plan to create a series of courses covering the various aspects Offspring boot and wanted to take a moment to go where the courts roadmap to let him know what is coming and what we will cover in each course. The full scores, springboard fundamentals, basics and getting started. We will introduce spring boot, cover its fundamental concepts, and we'll get started developing applications. We will see how to use spring initialize er rapidly build and run a simple Weber first and then a console application in the next course spring. Good fundamentals Creating a spring embassy app will build a fully functional spring, NBC App for Managing Item Elementary. We will implement the model service controller and view layers to show the items in wintry really use timely for the view layer. We will explain how to integrate third body libraries like Jake Witty, bootstrap, acceptable in our application and refer good model attributes in the view Earlier will also introduce Springboard Death Tools, which makes development investing easy in the next course springboard fundamentals. Connecting to read a base will continue building over AB and corrected toe a back end database using Springer the GP repositories. We'll start with anonymity, database H two and then later switched to my sequel to show how springboard makes it easy to work with religious databases and switch them at ease will create the ad update, delete operations and complete our spring Embassy AB. Creating timely views for adding in the leading along the way will further explore time. Leave template engine In the next course. Springboard fundamentals. Building and consuming arrest based Web services will demonstrate how spring boot makes it easy to create and consume rest services. We will create great dressed endpoints for the items in that invent tree. We'll then see how to consume rest FBI's In our springboard project. We will take the Web layer off our spring remesy app built earlier, and it sort of fetching data from Madrid. Abi's will display the front end consume later from the rest FBI's In the next course Springboard fundamentals. Monitoring health and metrics with actuators will demonstrate springboard actuators. Detroit is a lot of useful health endpoints and metrics right out of the box with zero according, we will show how to expose and enable the health endpoints. We'll see how to implement our own custom health checks and create new endpoints in the course Springboard fundamentals. Improving performance by implementing cashing, we will demonstrate the cashing support. Springboard provides with just a dependency and a few annotations who can be wise and effective cashing strategy for the application. We will first demonstrate the cashing with the fourth cash manager Springwood provides, and the later sparked the provider to read this in the course Springboard fundamentals. Implementing security. We'll see how springboard makes it easy to implement security. Well first demonstrated basic authentication. Well, then switch over App to use Didem is authentication. Springboard actuator Security is now integrated with the main apse security. We'll see how to predict actuator endpoints. We want to talk about the or to support in the course spring. Good fundamentals are configuration with profiles and deployment. Using docker, we will see how to configure or app for different environments like Devon Prawer using spring for files. We'll also see Holder Doc arise our application docker containers provide consistent development, build test and production environments and make running and deploying our APS very easy. I would recommend taking these courses in order, but if your family, with a certain aspect of string boot. You must skip that course and more to the next one. Further, if you just want to take the course for a certain aspect, it should be self sufficient to explain the concept without necessarily having to take the previous ones, though I will always recommend great the previous courses for a better understanding. So following these cities, of course, is you would have a solid conceptual, and it's turning off. The various aspects of this framework rapidly start developing applications and micro services. All right, let's not talk about the audience for the scores. 3. Audience: This course would be useful for Java and spring developers who want to understand spring boot and also for sort for architects who want to understand this powerful free work and how they should apply to their applications. What are the prerequisites to be most successful with scores? 4. Prerequisites: there are not a whole lot of produces its for the scores. The only thing you need is some basic Java knowledge and some basic spring concepts. Even if you do not have a lot of family already with these, don't worry. I will try to explain the concepts along the way, and you should be able to follow along without much difficulty. Let's next talk about the tools you will need to follow this course. 5. Tools: we will have a lot of demos in the scores as a believe that is the best way to learn the tools I would using. The scores are off course. Jama. I would be using open Judy Kay Warren, 11 but you can feel free to use Java or open Judy Kaye versions eight or above on. Most of examples should work for the i. D. E. I would be using Sprinkle Sweet, which is a flavor of eclipse but is highly customized and optimized for spring development . I would be using the version for it is open source and free and comes with a lot of bells and whistles. But I think you would like, however, if your family with and we like to use some other I d like intelligent etcetera, please feel free to do so. We will use spring boot version 2.1 point four for the databases. We will be using my sequel version 8.0 point 15 Red is is an open source in Memory Data Structures Tour used as a data base. Cash and message broker in this course will use readies for cashing. You can find the cold for the demos in the scores and the falling good Have you are 6. Demo: App overview: in this demo, it will take a look at the rest. AP I app were developed earlier in the course spring. Good fundamentals, building and consuming, arrest based Web services. Hair is arrest APP really had built rest API eyes to manage our item elementary and in the controller we had the realist rest endpoints To get all items, get a specific item in certain item of Dayton item and delete an item. Let's go toe arrested client to see how it works. First, let's call the http local host a deity slash FBI slash items to get all items, and we see her list of items returned in the Jason format. Let's call the FBI to get a single item. So after the path, the item i d Let's say two and a single atom French FBI is working just fine. Now let's are a new item. So change the method to post to the header that has add content type as application slashed his own in their Quest party, that is, choose custom that based the dis on here. I do not need to specify the item mighty as it will be generated. Modify the u. R L to remove Slash to let me hit send request and with your new item with I d created. Now if you go to the history, click the get forgetting all items and hits and request again We see Item 23 has been added That is now demonstrate the Porter operate operation. Let's change item price off waits to 10.99 So let me copy this change. The method to put Henry will be content. Time application slash Nissan request body will be custom didn't based that is on here Change the price to 10.99 and hit center Quist and it has been updated. There is very fire with the get call Go at a mighty one to us from the history for the get call Change the idea to one and clicks and request and we see that our upgrade was successful. Finally, let's see the delete operation in action. Let us delete at m I. T three, which we inserted earlier. So let me change the method or delete it expects it a quest parameter. So let me make the change with a question mark and value off ideas three Hittson and to see the success responds. Let's call the get all metal again. And indeed I the mighty three or deleted. Now let's add cashing to our application. 7. Demo: Adding caching to our application: and this demo, we will take the rest Web services we had created earlier and add cash in support to it. We will add the spring boot started gashed, open and see. Then we will go to the controller and are the religious cash, religion and traditions for the wiser. Cashing strategy. Finally, we were tested cashing in locations using arrest Client. I will be using the restroom extension or the Firefox browser. All right, let's get right to it. Here is the application we had built earlier where we had the rest based craft services. Let's open the bomber XML file and add the spring boots started Cash dependency Toe our file. Let us a great our project by right clicking, choosing maven and then update project. This one dependency will make springboard do most of the configuration of the cash manager for us, All we have to do is are the cash religion annotations Before you do that, let's go to our controller. Mattered and Al have mattered. Could delete all records define and at the lead mapping for slash lead. All create a metter delete. All do a system or print line to ST were deleting all items. Call the service may 3rd delete all and then return all items diligent. Successfully, we can put the cash, religion and traditions at several layers, like service controller etcetera. However, I like to put them in the controller layer. As that way, I avoid all unnecessary calls to the layers below, if not needed. First, let's go to our mean class and add the art. Enable cashing notation. What does its name states enables? Cashing spring boot will now look for cashing in notations throughout our court base. Next, let's start by adding the art cash able in addition in the get Mitter. This in addition, indicate that the results of this method call can be cashed. Using the value you can specify the cash name. You can specify multiple cash names. Comma separated. We specify the cash name here items. The cash essentially is a list off key value piers. Let's specify the key for this call as hash route. How harsh Root gives us access to the method, like met her name Arguments extra So saying Arc zero is then referring to the first parameter i D, which will be the key used at this point to understand the keys. Let's take a deter on the browser lets Google for spring dogs cash. Let's click this link from dark Start Springboard Io. This is a very good reference to understand cashing, and I will recommend you go through this header the different cash, religion and auditions, and we will be going through these. Here is the key generation strategy. If gnocchi is explicitly specified, then AKI's formed based on the method parameters. If there are no matter parameters than the key is simple kid out empty. If there is only one parameter, then it returns that instance. And if more than one parameters air present than a simple key is formed based on all of them. Off course, you can space for your own keys like as I was mentioning, Hash Root gives you top level access through which you can access and specify the method. Name our object, an object type or arguments as keys. You genetically differ a method argument by putting a hash in front offered. We will see how to do it and then hash result is a special keyboard, which allows us to access the result of the method call. So the metal returns the item object, then using it. We can specify hash result dot i d as the key, for example, so here it has specified the key as hash i d. Where ideas over parameter name. Let's fix the import that is big. The all dark spring framework got cash for the notations, not cash able for the import for the get all method, the cash using another cash name as all items. We're not specifying any key name. And since there are no parameters, the key is simply simple. Kid are empty for the post mapping. Very. In certain item, that is a game porter cashing in addition on What we want to achieve is that when a new item is inserted, then it is sporting other items cash. At the same time, we want our all Adams cash to be emptied as now the data and there is not up to date little devices strategy using two invitations inside or cashing an audition. So for port using cash for the notation, we put in the items cash the newly inserted item using the key as hash result. So upon insertion, the result will contain the newly created item and then we use a key as its item I d and then using evict we specify the cash victim notation with all items equal to true. To evict or empty the oil Adams cash the rate. Let's fix the import for the object method or put mapping using the cashing in notation We do a similar thing we did for insert So let me copy it from hair and paste it here. We're building the items cash with the result of the updated items item I D. And emptying the stale cash all items when we're deleting. We've warned the deleted item to be removed from the items. Cash as well is also empty The all items cash as it is not up to date. So he was in cash in an audition. We specify evict inside which using cash direct from the items cash we remove the key hash I d. And using cash evict from the all items cash we remove all the items now for the delete all operation again, you will use a notation similar to the delete operation only that this time we will evict all entries from the items cash along with the on Adam's cash. Finally, for our testing, let us create a method to clear the cache when we want. So there's map it to clear cache mapping. Using cashing a notation, we clear both caches. The method is a dummy. Met her from where were just returning cleared cache successfully there was Make sure we have system or print land calls in each method to let us know when a matter is being executed. So add get all in the get all matured Put a system out in the get matured in the ad Misheard also in the updated method Let's put a message of rigid item with I D and put the idea in there. Similarly, porter system out in the delete mattered indicating the idea being deleted. There is some better. Oh, it should be Item Don't get item I d. All right, let us now go and test If you were cashing Strategy is working. Let us start our app. Here is a stock version with the browser on top and the console view of the Spring tool suite and the bottom Let me open the arrested client. I have the restaurant client open on the browser. First, let us call the slash items endpoint. So issue dp local host 80 80 slash FBI slash items Mitya is get and here we see the response return which looking at the console out port, we see where matter was executed. Let us call this epi a again. Received a list of items returned back but no new system out in the console, indicating the results were obtained from the all items. Cash. Let us call the URL for the art mattered. Matter is post content type is application slash Jason. The body is custom where let him pace the Jason for the new item Click Sin and the scene the console that ever metals core. An insertion done here in the browser. If he's crawled down, we see our new item 83 hair. This execution has called the create method which has the cash porter notation which also puts it in the cash along with clearing the all items cash. So now when we call the get call for the newly created item using get call that sash items slash item idea of three with your items return and based on the console or port did not have to execute the method as it found the item in the cash where the create operation had put it with the same key name. Now let us get the details for item only one. It will not find it in the first execution from the cash so we're get metal is called. The first execution, however, are due to the cash with its key. The item I D. They're calling the get call again. The call would find it in the cash. So using the same key the I D across in certain abrade methods makes sense that way. The get matter uses it to find it from the cash. Next, let's a build the card for Item 81 and change the quantity to 30. The obit method got executed. The cash port will obey the cash with a key hash i D. As well as empty the all atoms cash. Let's make a get call for Item 81 again, and it does not execute the get mattered and obtains the result from the cash. Let's go on to get called for all items and we see the matter being executed, says the abused call emptied the cash. And so in this call to get the abridged values from the reader bees, let's call the get metal again. There is no system out in the console as it is, fetching it from the cash where the last call had put it. Finally, let me call the delete endpoint for after mighty three. So change the method or delete had sinned. The middle execute, removing it from the items cash as well as all Adams cash. Let us call the items in point to get all items. Since the cash was cleared, it is called again and see the leaders list of items. And this call has again filled the all atoms cash. So this is how using the cashing innovations we have devised an effective cashing strategy which ensures that the cash is used were possible at the same time ensuring that we do not get still results. Let us look at conditional cash in next 8. Demo: Conditional caching: in this demo river demonstrate Conditional cashing using the condition on unless keywords let me demonstrate the condition cured Richman optionally after the cash able. In addition, so only when this condition passes were the key be cashed. They support the condition that cash only when the item I d is greater than one see to it. A socially were not cashing out a mighty one back toe arrested client first, let's clear the cache by calling clear cash. Now let us call the FBI issued a p local host 80 80 slash items, not a mighty one method is get based on the console or port Visit the matter being executed in the u. R l again we see it is executed again. Let's change the item ready to to hit the sin. We see the matter being executed as it is the first call which will then added to the cash . Now let us hit the send again and it comes from the cash now, So cashing condition is working fine. Finally, let me introduce you to the endless condition which is again optional here. I can use the hash result, which is the result of the metal execution. So here the item object and then I'm using dot item prize An attribute of the item object to be greater than 1 40 Really? Unless as do not cash if the price is greater than 1 40 So since the price for item I t two is 1 49.99 it leads it to be not cashed Industrialist rate usage of the unless clause I can put here for the get all matter that do not cash If the results size is equal zero now the difference with unless is that it is evaluated offer the metal execution because only then the result object will be available Condition is evaluated before method execution based on parameters Now that is go back to arrested client first Clearly cash my calling clear Cash endpoint Now let us call http local host 80 80 slash FBI slash items slash to We see the matter being executed That is called it again and the matter is executed again as the on this condition is preventing it from being cashed Since the item price is greater than 1 40 Let's change the unless condition toe item prize greater than 1 50 Now our items should be cached since it surprises 1 49 for 99. No, let's go back to arrested client First clear the cache. My calling clear. Cash endpoint. Now there is called http local host 80 80 slash FBI slash items slash to We see the matter being executed. Let us call it again. And this time it pulls it from cash as there is no system out in the console. So in this demo we saw that how further using condition and unless clauses weaken tiller or cash in strategy Red is is an open source in memory. Did a structure store which can be used as a database or as a cash store or as a message broker? Now, for most production applications, you would use cash. Reuters like traders. Let us see how spring boot makes it easy for us to switch the cash provider 9. Demo: Switching the cache provider to Redis: in this demo, it will change the springboard starter Cash. The spring boot started leaderless dependency. Then we will indicate your amp the connection details to readers by modifying properties in the application or properties file. We will see the cache entries in the register. The base. Let's get started. I have the reddest server running locally on my machine, listening at Port 63 79. You can install release on your machine. Or, if you're using Docker, you can pull in. The docker image with red is to run it on your machine. Let's first stop our application. Let's open our former XML file. You were using the basic cashing earlier, using the dependency Springboard starter Cash. Let's go meant Springboard started cash and include a new dependency to springboard started . It already is. Let us right click on our Project Jews maven and then Abate Project Next, another application or properties file. Let us indicate the spring boot that we're using radios for cash. Let him paste these lines using spring broadcast or type of indicate that we're using Red is as the cash provider host is. Local host board it is listening to is on 63 79. The remaining properties are optional. Using spring dot cash or red is not cash hyphen null equal to falls. We tell readers not to cash naled values when they killed the time to live, or the time after which the cash values should expire, which is 10 minutes here or 600,000 milliseconds. The last entry off use Dark Edo perfects if said, too true would preparing the key name with the cash name. So for cash names, my cash and our key name is Mikey. Then it will store the key as my cash. My key ah, false value simply stores a key as my key without the cash name being pretended to see all the possible cash related properties. Let's Google spring boot cash properties and to see the appendix on Dark starts printed Io website. Here, you can see all the common application properties, and here are the cash related properties, some for specific Reuters wrecked graders or coach ways and some general like cash names. So back to our project, the reddest dependency and the properties is essentially all we had to do to switch the cashing to reddest spring boot order configures everything else and I will existing in notations in our application will work just fine. Let's start our app. Let me open a terminal window and run the reddest command line interface using Raiders. Haven't see Ally. He was in the keys. Astra Command with you, The keys it has. And currently there are no keys here. I have the browser and the spring tool suite console stacked so we can see the messages in the console as we execute the u. R l let me open the restaurant client. Let's call the issue dp local host it deity slash FBI slash items to get all items and I see all the items receive the message and console getting record. That is because our Guettel endpoint executes the method where we're putting the system out because of the cash able in notation. It is cached since there are no matter parameters and we have not specified the key, the key will be simple entry. If we had the u R l the next time we do not see any message. So this time it is pulling it from cash in the reddest command line interface using the keys. Astra command. We see the keys it has and hairs of a simple key for the get all matter pretender by the cash name All items back toe arrested client that has now hit the euro to get a specific item. So after the path, the item i d Let's say two metal is executed, which also are the two cash If we hit the u. R L again, we see it did not execute the method again. It is getting it from cash going to read his command and in the face again and running the keys. Astra Command. We see our new key cash name items and then our key for after mighty too. I would not go and demo other MP calls as it would exhibit the appropriate cashing behavior as it would do with the default provider. The only difference is that this time it is using red is as a cash breuder. And as you can see, we did not have to modify over cool at all, and spring boot made it so easy for us to switch 10. Summary: in this course, we started off talking about the audience tools and prerequisites for the scores reentered the spring boots under cash dependency to our project, which makes spring boot or to configure the default cash manager For our app, we saw the cashing in notations like Ashley Able cashing cash, Port Cash A verdict which help US device an effective Kachin strategy we saw conditional cashing with the condition. And unless keywords Finally we saw how easy springboard makes it to switch the Kachin provider risk Twist it to read this In our case, I enjoyed making the scores and I hope you found the scores helpful and understanding. Cashing with spring boot. Thanks for watching and see you next time.