Fast loading of data on the home page, solutions for accessing public resources

Fast loading of data on the home page, solutions for accessing public resources

        Homepage data is a very important key point for a project, why? There is no doubt that the home page will be visited more than other pages in most cases. If the request for the home page data is a real .do request, then there will be a problem, that is, as long as the home page data is loaded, it will access the server. Whether the server uses the cache or directly queries the database, it will cause Overhead of resources (big or small issues). If so, what problem do we need to solve?

        If the resource is a public resource, we will extract this part, generate a static file, and then give the url address for the client to access. It doesn't matter whether the xml format or json format is in the format, and add a serverTime attribute or field. This thing is a timed task that our backend runs or an executable method that can be spawned. To generate a specified directory regularly, this directory will be proxied by nginx, that is to say, if our resource is public, we will use this strategy of generating a static file for everyone to access. Of course, it is best to make a caching mechanism on the client side. In the absence of a network, we need to display locally cached data.

        If this file request contains a part about the user's personal information (different people show different effects), please separate it from the static file. The atomicity of this request is guaranteed.

        Of course, since we have cached on the client, we need to use the update strategy of the client. We have the attribute or field serverTime in the file, which is the time generated by the server when the file is generated, and this time is stored in redis Or in this other memory, when the client (timed access or this refresh) comes to visit whether we need to update, give him the time, let them compare the time by themselves, and then decide whether to revisit the corresponding public resource. the address of. In this case, the amount of data is extremely small each time it is accessed, it will not be updated when it is not needed, and it will be updated when it needs to be updated.

        Because I personally think that public resources have no permissions, and the effects or data displayed by everyone are always the same, there is no need to use dynamic interfaces, and using files will reduce the pressure on tomcat, thereby better improving the effective work efficiency of the server.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324407400&siteId=291194637