0

I've got 110 records (3.3 kB) in my database, they will never change, and I'm calling them quite frequently during the user journey.

For this reason, I thought to store them into a cache system (file), but, looking at the network performance, the same call from the DB takes 150ms, instead the one from the cache more than 300ms.

I'm not really worried about the user experience, 150ms is nothing (IMHO), but I'm concern about how much computing is requested by the server. By the results I understand that the cache is more "expensive" than the DB.

Does anyone know if this is the case or not? Which one of the two would you use?

Thank you.

Ale
  • 117
  • 1
  • 13
  • If you want it to be really fast, then you can use an in-memory key/value store, like redis/memcached/APCu or similar. if the speed doesn't really matter, then just use what what's easiest for you. I doubt any of the alternatives will cause any real issues regarding "how much computing" that's needed. No need to micro-optimize your code unless you notice some actual issue. – M. Eriksson Sep 18 '21 at 20:12
  • Thank you @MagnusEriksson, but I'm not looking for a faster process, but for a more efficient for the server. Probably the ones you've suggested are more efficient as well, but, in my specific case, which one is the best? – Ale Sep 18 '21 at 20:16
  • 1
    It's pretty hard to say which is "best" for you without some more benchmarking. Different systems behave differently (CPU speed/memory/file system speed etc) But unless you actually have some issue, just go with what's easiest. Premature optimization should be avoided. – M. Eriksson Sep 18 '21 at 20:17
  • 1
    If these things will truly never change, and you want to optimize things, then bake them into your PHP code itself. Zero network latency. I’m guessing your cache perf is related to deserialization. – Chris Haas Sep 19 '21 at 01:46
  • Thank you guys for you answers. At the end I opted to store the data in the Client's localStorag. As I said it's just 3.3kB and it's not sensitive data. – Ale Sep 20 '21 at 08:20

0 Answers0