samedi 5 septembre 2020

Is there a pattern in spring which allows to use data from remote server in several services without requesting it many times?

I'm trying to create CRUD endpoints for entity A. This entity has a field with collection of ids of another entity B. Entity B lives on remote server.

I want to

  1. Validate that entities B with passed ids actually exists on remote server.
  2. Save in local database both fields of entities B: id and name

name of entity B can be received from remote server via endpoint. And via this endpoint I can validate that entities B with passed ids exists on remote server.

In my app I tried to separate the logic, so there is one spring component for validating entity B and other for mapping from DTO representation of entity A to internal representation.

And I need to call remote server with the same request for both purposes: for validation of existence and for mapping with id and name on entity B.

I have an idea with short time cache, but it seem odd to me to use cache for such purpose.

Other way is to call this endpoint in some upper service and pass received data to validator and to mapper, but with such implementation upper service need to know this internal details of validator and mapper (that they need information from remote server)

Is there an other way around to do it with spirng?

Thank you!

Aucun commentaire:

Enregistrer un commentaire