Can Session State cache an object (e.g., a client_writable() view)?

Reference:
https://anvil.works/doc/#server_module_session_state
https://anvil.works/doc/#data_tables_views

Rationale:
Client-writable views seem like a great thing to use, even server-side. If we create the views at log-in time, then the rest of the session’s code can work with just the views. By never accessing the underlying tables directly, such code guarantees that it is working only with the right user’s data.

Ideally, the view objects will persist, in the session, between server calls. Otherwise, they have to be re-created on demand, which seems rather wasteful. Hence the wish to cache them.

In general, what kinds of objects – if any – can be cached in an anvil.server.session?

Yes, you can store Client Writeable Views in the session state.

anvil.server.session can store anything that a server function can return, except for Media objects.

This wasn’t in the docs, I’ll update them :slight_smile:

(Here’s an app that demonstrates storing a view in the session object.)

https://anvil.works/build#clone:F4X5XR4VYKOPZLXL=C6GFCZ5ZR7GP7ATLHDFGBRNB

Some Services, schema, and users required, but I definitely see. Thanks!