mevdschee / php-crud-api

Single file PHP script that adds a REST API to a SQL database
MIT License
3.6k stars 1.01k forks source link

Insights on caching with Redis #1020

Closed violamassimoINGV closed 7 months ago

violamassimoINGV commented 7 months ago

Hello, I'm trying to use Redis caching with a cacheTime of 300s to balance the load on relational PostgreSQL databases.

While using the caching system, I noticed that the system saves three records in Redis:

/data # redis-cli KEYS "*"
1) "phpcrudapi-f0b4f766-e4cfba82f5ecb84eb9d4375b8d204a11-ReflectedTable(vt_lt_fof)"
2) "phpcrudapi-f0b4f766-e4cfba82f5ecb84eb9d4375b8d204a11-ReflectedDatabase"
3) "phpcrudapi-f0b4f766-PathTree"

And for each call different from the previous one, if on the same database and different table, only the table structure (ReflectedTable record) is cached.

Could you provide clarification on how the cache works? What are the advantages of enabling this type of cache?

mevdschee commented 7 months ago

This API uses reflection to determine what endpoints are available. Reflection on the database requires querying the information schema. Those queries are used to find relations between tables and can be expensive. The cache reduces the number of reflection queries that need to be done. The actual table data is not cached. I hope this explains everything. Kindest regards, Maurits

violamassimoINGV commented 7 months ago

I thank you for the comprehensive explanation. We use the product developed by you, and having reviewed the code, I can only offer my compliments for the solutions adopted. I am closing the issue and thank you once again.