tapesty persistence strategy

http://tapestry.apache.org/tapestry5/guide/persist.html

Most instance variables in Tapestry are automatically cleared at the end of each request.
通常每次请求结束,Tapestry会将实例变量清空。

This is important, as it pertains to how Tapestry pages are pooled and shared, over time, by many users.
这很重要,因为Tapestry的页面是在缓冲池中被许多用户共享的。

However, you often want to store some persistent data on a page, and have access to it in later requests.
然而,你通常希望在页面存储一些持久数据,这样后面的请求可以得到这些数据。

This is accomplished with the Persist annotation.

This annotation is applied to private instance fields.

  @Persist
private int value;

Annotated fields will store their state between requests. Generally, speaking, this means that the value is stored into the session (but other approaches are possible).

Whenever you make a change to a persistent field, its value is stored.

On later requests, the value for such persistent fields is reloaded from storage.



Persistence Strategies

The value for each field is the strategy used to store the field between requests.

session strategy

The session strategy stores field changes into the session; the session is created as necessary.

A suitably long session attribute name is used; it incorporates the name of the page, the nested component id, and the name of the field.

Session strategy is the default strategy used unless otherwise overridden.

Session策略是默认策略。

flash strategy

The flash strategy stores information in the session as well, just for not very long. Values are stored into the session, but then deleted from the session as they are first used to restore a page's state.

The flash is typically used to store temporary messages that should only be displayed to the user once.

client strategy

The field is persisted onto the client; you will see an additional query parameter in each URL (or an extra hidden field in each form).


Client  持久花费的代价要高些,它会在渲染页面的每个链接后面加上数百字节的额外信息。

Client persistence is somewhat expensive. It can bloat the size of the rendered pages by adding hundreds of characters to each link. There is extra processing on each request to de-serialize the values encoded into the query parameter.

Client persistence does not scale very well; as more information is stored into the query parameter, its length can become problematic. In many cases, web browsers, firewalls or other servers may silently truncate the URL which will break the application. 有时URL地址太长会被截掉。

Use client persistence with care, and store a minimal amount of data. Try to store the identity (that is, primary key) of an object, rather than the object itself.

你可能感兴趣的:(tapesty persistence strategy)