search

Home  >  Q&A  >  body text

Can nginx implement content-based caching for POST requests?

Because it is a webservice and the content of the post is json, the commonly used API interfaces need to be cached. I wonder if it can be done at the nginx layer?

黄舟黄舟2783 days ago673

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-05-16 17:31:34

    Yes, the working mode of nginx at this time is a response agent, but it is not suitable

    First of all, you need to know how you want to cache the content. For example, if the input is the same (same user cookie, same http post parameters), how long will it take for the cached content to expire? To implement such a configuration file, it is almost as simple as writing code, then Why not write it in python or php

    Where is the cache stored? Assuming that you have done all the above things with the configuration file, where do you want to put the built-in cache? Disk or memcache, it seems to be a programming job.

    If you feel that it is appropriate to use nginx to do these things, please continue. Otherwise, implement it in the code and try to make the nginx configuration file as simple as possible. Use PHP (fastcgi) or python to use memcache for caching, and the efficiency is still the same Quite high, at least a little faster than the cache speed of nginx for reading files. After all, it is a memory operation

    reply
    0
  • Cancelreply