I am developing a service using Spring Boot (with Java) and I have the following requirement: The service (when invoked) must generate a timed UUID associated with a string that I pass as input to the service. For example, if I invoke the service like this (with a Http GET):
http://localhost:8080/myService?param=example
The service returns me a UUID like 55bcbfce-8984-4f1d-8435-f9548baf8cb5.
The fact is that I want to implement a caching system that stores (for a limited time, like 5 seconds) this UUID along with the passed string example.
So, a "table" stored in the application would be such a thing like this:
| UUID | param | duration |
|---|---|---|
| 55bcbfce-8984-4f1d-8435-f9548baf8cb5 | example |
3sec |
| 07ef2e6e-e6a1-45e7-b6a6-51dfab49f782 | example2 |
2sec |
Like this, a second service I call by passing it a UUID as input, like this:
http://localhost:8080/mySecondService?UUID=55bcbfce-8984-4f1d-8435-f9548baf8cb5
It could return me (if invoked in the right time) the param associated with the UUID 55bcbfce-8984-4f1d-8435-f9548baf8cb5, that is example. If the time is up, then the second service returns an error.
My question is: is there an easy way to implement this WITHOUT USING A DB, but using just a small caching system (the memory will be shared between the two services!)? I am new to both Spring Boot and caching, and have never used cache before. I simply cannot use a DB in this situation.