mercurius-js / cache

Adds an in-process caching layer to Mercurius. Federation is fully supported.
MIT License
106 stars 19 forks source link

feat: add federation and gateway examples #135

Closed anapaulalemos closed 1 year ago

anapaulalemos commented 1 year ago

Closes #82

simone-sanfratello commented 1 year ago

I suggested to have cache on federated services and on the gateway, and to use invalidation on them, so redis is needed to share the cache between them, and to keep the cache consistent by the invalidation, so invalidating entries on the federated services on writings (create post in this case) automatically invalidates the entries on the gateway too.

We can go with simple solution, but imo can be more significant using invalidation

simoneb commented 1 year ago

@brainrepo can you please review this PR?

simone-sanfratello commented 1 year ago

This example doesn't work properly, there's no invalidation on the gateway.

Calling topPosts, then createPosts, then topPosts again, you get the old values.

anapaulalemos commented 1 year ago

This example doesn't work properly, there's no invalidation on the gateway.

Calling topPosts, then createPosts, then topPosts again, you get the old values.

Fixed. I also changed all the references for the sake of simplicity.

simone-sanfratello commented 1 year ago

I don't agree with the fix, removing the cache from gateway works, of course, but this is not the target of providing an example for the cache feature.

The example should be a showcase of "how to use the cache in a federated scenario", and we can achieve that through invalidation, adopting the cache on the gateway and on the federated services.

simoneb commented 1 year ago

can you please rebase this PR on top of master? it's missing some changes that were merged previously