1

I'm making a CRUD application that uses PostgreSQL as the primary store and uses Redis as a cache. For this part of the application, the API pulls all its data from the Redis cache.

This has worked fine for reading from Redis, but now I want the changes that are committed to the database during a create/update/delete to be immediately reflected in the Redis cache. I'm unsure about how to do this, or if this is even the best way to do it.

Could someone please provide an example of how to achieve this?

1 Answer 1

2

First of all it's largely unnecessary. A well designed PostgreSQL database is fast and there is no need to arbitrarily cache every single query. You have have certain queries that are slow and cannot be optimized, you can cache them into redis at the application level as you know.

If you insist on caching everything you need foreign data wrappers available since postgresql 9.3. On that page you will find links to two redis FDWs. You will still need to write a hell of a lot of triggers.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. I'm very new to the backend, and I've been obsessing with performance. I really was hoping to get an answer like this telling me that I was looking at it the wrong way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.