Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alexz006 opened this issue Feb 23, 2021 · 2 comments
Open

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

alexz006 opened this issue Feb 23, 2021 · 2 comments

Comments

@alexz006
Copy link

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 alexz006 reopened this Feb 23, 2021
@leafo
Copy link
Owner

leafo commented Feb 23, 2021

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

leafo added a commit that referenced this issue Feb 24, 2021
@alexz006
Copy link
Author

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants