在应用程序完全可用之前填充缓存

Populate cache before app is fully available

是否有 uWSGI option/hook/subsystem 可以在应用程序准备好处理请求之前填充缓存? 静态 load-file-in-cache 不是一个选项。我需要调用填充 uWSGI 缓存的函数或程序。

先决条件是 uWSGI 实际上启用了缓存,例如:

[uwsgi]
cache2 = name=mycache,items=100

启动挂钩有很多选项。看看this page in the uWSGI doc。你可以选择在uWSGI启动序列中的什么点你想连接(as-root, as-user, pre-app, accepting1, ...)并且你有选择权在 shell exec (exec) 和函数调用 (call) 之间。

配置指令可能类似于:

[uwsgi]
call-as-root = cache_clear("mycache")
call-as-user = cache_set("key", "value")

另见 Cache functions

我相信 load-file-in-cache 指令也可以解决您的问题:

[uwsgi]
exec-as-user=/usr/local/bin/populate_my_cache_folder.sh
for-glob = /my/cache/folder/*.*
    load-file-in-cache = files %(_)
endfor =