From the course: .NET Microservices for Azure Developers

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Solution: Implement a new endpoint and memory cache

Solution: Implement a new endpoint and memory cache - Azure Tutorial

From the course: .NET Microservices for Azure Developers

Solution: Implement a new endpoint and memory cache

(upbeat music) - [Instructor] Let me show you how I solved the challenge. First, in the pets controller class, I added this update method that is receiving a pet update object. And this is a record that has the name, the age, and their breed ID, and I'm searching for that particular pet in the DB context. And of course, I'm validating if the pet exists, in which case I'm updating the name, the age, and the breed ID, and then saving the changes back to the DB context. Then, in the clinic application service class, I'm injecting IMemoryCache and I'm using it's get or create async method for storing the pet info object. And you can see that I'm using absolute expiration relative to now in 30 seconds. In other words, the object will be refreshed in the cache every 30 seconds. In the meantime, if you send a request, then the clinic microservice is going to use the object from the cache. And finally, here in the program class, I'm invoking add memory cache, which is the default…

Contents