thread_store.rst 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. ===================
  2. Misago Thread Store
  3. ===================
  4. Thread store is simple memory-based cache some Misago features use to maintain state for request duration.
  5. .. warning::
  6. :py:mod:`misago.core.threadstore` is considered part of internals and generally should be avoided unless
  7. It offers subset of standard cache API:
  8. get
  9. ---
  10. .. function:: get(key[, default=None])
  11. Get value for key from thread store or default value if key is undefined.
  12. >>> from misago.core import threadstore
  13. >>> get('peach')
  14. None
  15. >>> get('peach', 'no peach!')
  16. 'no peach!'
  17. get() never raises an exception for non-existant value which is why you should avoid storing "None" values and use custom default values to spot non-existant keys.
  18. set
  19. ---
  20. .. function:: set(key, value)
  21. Set value for a key on thread store. This value will then be stored until you overwrite it with new value, thread is killed, :py:mod:`misago.core.middleware.ThreadStoreMiddleware` process_response method is called, or you explictly call clear() funciton, clearing thread store.
  22. clear
  23. -----
  24. .. function:: clear()
  25. Delete all values from thread store. This function is automatically called by ThreadStoreMiddleware to make sure contents of thread store won't have effect on next request.