lapis icon indicating copy to clipboard operation
lapis copied to clipboard

cache.lua:71: attempt to index local 'dict' (a nil value)

Open alexz006 opened this issue 3 years ago • 2 comments

OpenResty 1.19.3.1, Lapis 1.8.3.

New project:

lapis new --lua
wrote   nginx.conf
wrote   mime.types
wrote   app.lua
wrote   models.lua

app.lua:

local lapis = require("lapis")
local cached = require("lapis.cache").cached

local app = lapis.Application()

app:match("/microcached", cached({
  exptime = 1,
  function(self)
    return "hello world!"
  end
}))

return app

GET /microcached?foo

Error
...cal/openresty/luajit/share/lua/5.1/lapis/nginx/cache.lua:71: attempt to index local 'dict' (a nil value)
Traceback
stack traceback:
	...cal/openresty/luajit/share/lua/5.1/lapis/nginx/cache.lua:71: in function 'handler'
	...cal/openresty/luajit/share/lua/5.1/lapis/application.lua:146: in function 'resolve'
	...cal/openresty/luajit/share/lua/5.1/lapis/application.lua:183: in function <...cal/openresty/luajit/share/lua/5.1/lapis/application.lua:181>
	[C]: in function 'xpcall'
	...cal/openresty/luajit/share/lua/5.1/lapis/application.lua:189: in function 'dispatch'
	/usr/local/openresty/luajit/share/lua/5.1/lapis/nginx.lua:231: in function 'serve'
	content_by_lua(nginx.conf.compiled:22):2: in main chunk

You need nginx.conf add the line:

http {
  lua_shared_dict page_cache 10m;
  ...
}

and then everything works.

alexz006 avatar Feb 23 '21 10:02 alexz006

This sounds like an update for docs might be needed? And perhaps a better error message?

leafo avatar Feb 23 '21 23:02 leafo

This sounds like an update for docs might be needed? And perhaps a better error message?

I think that when creating a new project (lapis new), the line lua_shared_dict page_cache 10m; was added by default in the nginx.conf file;

alexz006 avatar Feb 24 '21 11:02 alexz006