You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

69 lines
2.2 KiB

  1. # Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. #
  3. # MIT License (MIT)
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a
  6. # copy of this software and associated documentation files (the "Software"),
  7. # to deal in the Software without restriction, including without limitation
  8. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. # and/or sell copies of the Software, and to permit persons to whom the
  10. # Software is furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. #
  22. from __future__ import unicode_literals
  23. """
  24. Boot session from cache or build
  25. Session bootstraps info needed by common client side activities including
  26. permission, homepage, control panel variables, system defaults etc
  27. """
  28. import webnotes
  29. import conf
  30. import json
  31. @webnotes.whitelist()
  32. def clear(user=None):
  33. """clear all cache"""
  34. clear_cache(user)
  35. webnotes.response['message'] = "Cache Cleared"
  36. def clear_cache(user=None):
  37. """clear cache"""
  38. webnotes.cache().flush_keys("bootinfo:")
  39. webnotes.cache().flush_keys("doctype:")
  40. # doctype cache
  41. from webnotes.utils.cache import clear
  42. clear()
  43. # rebuild a cache for guest
  44. if webnotes.session:
  45. webnotes.session['data'] = {}
  46. def get():
  47. """get session boot info"""
  48. # check if cache exists
  49. if not getattr(conf,'auto_cache_clear',None):
  50. cache = webnotes.cache().get_value('bootinfo:' + webnotes.session.user)
  51. if cache:
  52. cache['from_cache'] = 1
  53. return cache
  54. # if not create it
  55. from webnotes.boot import get_bootinfo
  56. bootinfo = get_bootinfo()
  57. webnotes.cache().set_value('bootinfo:' + webnotes.session.user, bootinfo)
  58. return bootinfo