There are some strategies of caches for web applications. These same strategies can be applied for microservices. The most common strategy for caching is when we store the information in a cache after a query. In the following diagram, we receive a request through our API and we will, in the application, make the data query. The first search is performed in the cache and, if the data is not in the cache, the search is performed in the database. To return the query from the database, the value is recorded in the cache:
This kind of strategy is the simplest cache that can be applied. We see the changes we should make in our application to have the cache layer.
The first step is to download dependency with Redis as the connection driver:
$ go get github.com/garyburd/redigo/redis
The Redigo is our communication interface with Redis. We will use Redis as a cache tool of our microservice.
Now, we will create the cache.go
file. This file is responsible for delivering...