python - django 在哪里加载参数资源
PHP中文网
PHP中文网 2017-04-17 15:01:21
0
1
495

程序运行逻辑需要一些配置,比如说一些城市列表,学校列表等。产品那边把这些配置在 excel 里。我写了个工具导出成 json 文件。

两个问题
1. django 什么地方加载这些资源配置呢?
2. django 有的时候是新起一个进程来处理新连接的,难道要每个新进程都要加载一遍么???!!!这样太消耗 IO 了。

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
Ty80

It may not be possible to answer the two questions you asked

  • I think we should first look at how many of these things there are. If there are many, they can be placed directly in the database. If there are not too many, there is no problem in recording them in files like you do.
  • Then the timing of loading is to load when in use and to preload when the process starts. The former is more suitable for scenarios where there is a lot of data and not all of them are commonly used, while the latter is for scenarios where the number of transaction receipts is small but frequently used.
  • Then the storage location, if there is not too much data and it is used very frequently, can be directly made into a singleton and placed in the memory, one for each process; in the opposite case, you can consider getting it directly from the database, or using memcached/redis To do distributed caching.
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template