Pages
The functions and macros to work with pages are defined in the
REBLOCKS/PAGE
package.
Page life-cycle
When user opens a new page of the app, init-page
generic-function
get called. It should return or root widget or an object of page
class.
If variable *pages-expire-in*
is not NIL
, then page will be deleted from memory
after this number of seconds. Hovewer, each action call extends expiration time
to *extend-page-expiration-by*
seconds.
A variable *max-pages-per-session*
controls the maximum number of pages in one user
session. Older pages will be expired at the moment, when user tries to open a new page.
These settings are NIL
by default, but may be used to protect server for DoS attacks
where attacker tries to fill all server memory with useless pages.
If you define your own page class, then you can define
page-expire-in
, extend-page-expiration-by
and max-pages-per-session
generic-functions
to control how long page should live.
Page metadata
Any data can be associated with a page. For example, dependencies loaded into the page are saved into the metadata, to avoid assets duplication.
You can get current page using current-page
function and then retrieve metadata with
page-metadata
and change it using (SETF
page-metadata
) or ensure-page-metadata
macro.
Warning, if there are some parallel threads which might change metadata
then you should wrap all changing code in with-metadata-lock
macro.
API
A method for this generic function should be defined to initialize a new page object.
It should return a widget which become a root widget of the page or it might return the
page with initialized root widget in case if you want to use your own subclass of the page
class.
This generic function gets called when user refreshes page in the browser.
Default method does nothing.
This generic function gets called when user loads a page in the browser. It is called for all non Ajax requests.
When user reloads page multiple times, the page object can be reused. Thus this function may be used to reset some page attributes.
Default method resets a list of loaded dependencies to ensure that all of them will be sent to the browser again.
This generic function gets called when user get's a redirect to another page.
Default method does nothing.
Returns NIL
or a number of seconds after which page should be removed from the memory.
Default method returns current value of *extend-page-expiration-by*
variable or *pages-expire-in*
variable.
Returns NIL
or a maximum number of pages to keep in the session.
Older pages will be expired and free memory.
Default method returns current value of *max-pages-per-session*
variable.
Returns NIL
or a number of seconds after which page should be removed from the memory.
Default method returns current value of *pages-expire-in*
variable.
Should return a string of CSS
classes for the body HTML
element or NIL
.
Returns a metadata with NAME
, bound to the current page
Extends expiration time of the current page.
Returns current page object. Can be useful to pass to call page-metadata
.
Returns a page from a current session by it's id.
Returns T when current-page
function will be able to return page instead of throwing an error.
Like page-metadata
, but if metadata piece with NAME
is not found saves the DEFAULT
before returning it. Secondary return value is true if NAME
was
already in the metadata.
A number of pages per session. When it is reached, oldest pages and their actions will be expired.
If NIL
, then actions will live in memory forever.
A number of seconds before page and it's actions expiration.
If NIL
, then actions will live in memory forever.
A number of seconds to be added to current page expiration time when a new action is processed.
After an action processing page expiration time either will remain the same or become equal to (+ (now) extend-page-expiration-by).
By default, the variable is unbound and the value of *pages-expire-in*
is used.
A number of seconds between expired pages cleanup.