I've opened an issue because I think it could be a bug: https://github.com/web2py/web2py/issues/2266
I'll try to suggest a fix. El viernes, 18 de octubre de 2019, 21:16:17 (UTC-3), Lisandro escribió: > > When using @cache.action in controller functions, the key used for storing > the content is auto-generated based on the request URL. To be more > specific, the key is generated based in *current.request.env.path_info* and > *current.response.view:* > > https://github.com/web2py/web2py/blob/1ce316609a7a70c42dbd586c4a264193608880ba/gluon/cache.py#L614 > > However, I'm seeing this issue. > Let's say we have a website that has articles splitted into several > categories. > We also have a controller function that exposes the articles given a > category ID passed as first argument in the URL: > > @cache.action(cache_model=cache.redis, session=False, vars=False, public= > True) > def category(): > cat = db.categories(request.args(0)) > articles = cat.articles.select() > return response.render(dict(cat=cat, articles=articles)) > > > This works as expected, however I've noticed that a different key is > generated for this two URLs: > /default/category/10 > /default/category/10/ > > Notice one of the URLs has a trailing slash. > I'm using Redis for caching, and I've checked the stored keys and they are > different. > *The issue here is that both URLs produce the exact same content, but the > content is cached twice with different keys.* > > > In my case, the problem is even worst, because I add a slug to the URL > with the name of the category, like this: > /default/category/10/technology > > In this case, the slug is added just to make the URL prettier, so it > doesn't really matter what is provided in the second argument. All these > URLs produce the exact same content: > /default/category/10 > /default/category/10/ > /default/category/10/technology > /default/category/10/anything-at-all > > In a public website, a bot could send all types of random requests, thus > provoking the server to use a lot of RAM for caching several copies of the > same content. > > So I'm wondering, wouldn't be nice to be able to specify the key? Or at > least be able to say which of the args should be consider to create the > key? > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/6d18bd55-fdcf-4a74-a6c8-167f216b3dae%40googlegroups.com.