Shared Memory Dictionaries
Cache data across workers with ngx.shared.DICT for low-latency lookups.
What Is ngx.shared.DICT?
ngx.shared.DICT is a shared memory zone accessible by all Nginx worker processes. It provides O(1) get/set/incr operations for caching and coordination.
Declaring Shared Memory in nginx.conf
Allocate shared dictionaries with a name and size in the http block.
# nginx.conf
http {
lua_shared_dict rate_limit 10m;
lua_shared_dict cache 50m;
lua_shared_dict locks 1m;
}All lessons in this course
- OpenResty Architecture
- Handling HTTP Requests in Lua
- Cosockets and Non-Blocking TCP
- Shared Memory Dictionaries