Scala web :: lazy val scope/lifetime

2019-09-07 07:52发布

In a Scala web application, is lazy val scoped to the lifetime of the application server, or request scoped?

I assume it is per request, but have not been able to find a definitive answer, thus the question.

Thanks

1条回答
唯我独甜
2楼-- · 2019-09-07 08:26

lazy is a Scala feature, not related to web application programming. It means: evaluate only once on first access. If the variable is part of an object created per request, it will be lazily evaluated once per every request.

If it is declared inside application-wide class (or object), once evaluated it will keep its value as long as the class is loaded (so probably the WAR lifetime).

查看更多
登录 后发表回答