stash.rst (1065B)
1 Stash 2 ===== 3 4 Object for storing cross-request state. This is unusual in that keys 5 must be UUIDs, in order to prevent different clients setting the same 6 key, and values are write-once, read-once to minimize the chances of 7 state persisting indefinitely. The stash defines two operations; 8 `put`, to add state and `take` to remove state. Furthermore, the view 9 of the stash is path-specific; by default a request will only see the 10 part of the stash corresponding to its own path. 11 12 A typical example of using a stash to store state might be:: 13 14 @handler 15 def handler(request, response): 16 # We assume this is a string representing a UUID 17 key = request.GET.first("id") 18 19 if request.method == "POST": 20 request.server.stash.put(key, "Some sample value") 21 return "Added value to stash" 22 else: 23 value = request.server.stash.take(key) 24 assert request.server.stash.take(key) is None 25 return value 26 27 :mod:`Interface <wptserve.stash>` 28 --------------------------------- 29 30 .. automodule:: wptserve.stash 31 :members: