diff --git a/js/legacy/widgets/form/form.js b/js/legacy/widgets/form/form.js index b275b75154..c47c962bd6 100644 --- a/js/legacy/widgets/form/form.js +++ b/js/legacy/widgets/form/form.js @@ -1108,7 +1108,7 @@ _f.set_value = function(dt, dn, fn, v) { var frm = wn.views.formview[d.parenttype].frm; } else { locals[d.doctype][d.name].__unsaved = 1; - var frm = wn.views.formview[d.doctype].frm; + var frm = wn.views.formview[d.doctype] && wn.views.formview[d.doctype].frm; } if(frm && frm==cur_frm && frm.frm_head) { diff --git a/py/webnotes/session_cache.py b/py/webnotes/session_cache.py index c76f0f5a6a..e317efb720 100644 --- a/py/webnotes/session_cache.py +++ b/py/webnotes/session_cache.py @@ -31,20 +31,25 @@ import webnotes @webnotes.whitelist() def clear(user=None): """clear all cache""" + import webnotes clear_cache(user) webnotes.response['message'] = "Cache Cleared" def clear_cache(user=''): """clear cache""" + import webnotes if user: webnotes.conn.sql("delete from __SessionCache where user=%s", user) webnotes.conn.sql("update tabSessions set sessiondata=NULL where user=%s", user) else: webnotes.conn.sql("delete from __SessionCache") webnotes.conn.sql("update tabSessions set sessiondata=NULL") + + # doctype cache + import webnotes.utils.cache + webnotes.utils.cache.clear() # rebuild a cache for guest - if webnotes.session: webnotes.session['data'] = {} diff --git a/py/webnotes/utils/cache.py b/py/webnotes/utils/cache.py index 647f047fda..124db80991 100644 --- a/py/webnotes/utils/cache.py +++ b/py/webnotes/utils/cache.py @@ -33,6 +33,10 @@ setup() sets up cache import webnotes +def clear(): + """clear doctype cache""" + webnotes.conn.sql("""delete from __CacheItem""") + class CacheItem: def __init__(self, key): """create a new cache""" @@ -57,8 +61,5 @@ class CacheItem: def clear(self): """clear the item""" - try: - webnotes.conn.sql("delete from __CacheItem where `key`=%s", self.key) - except Exception, e: - if e.args[0]!=1146: # ignore table not existing - raise e + webnotes.conn.sql("delete from __CacheItem where `key`=%s", self.key) + diff --git a/wnf.py b/wnf.py index 93c2c5b99e..bbe884b361 100755 --- a/wnf.py +++ b/wnf.py @@ -130,9 +130,6 @@ def setup_options(): parser.add_option("--replace", nargs=3, default=False, metavar = "search replace_by extension", help="file search-replace") - - parser.add_option("--cci", nargs=1, metavar="CacheItem Key or all", - help="Clear Cache Item") parser.add_option("--sync_all", help="Synchronize all DocTypes using txt files", nargs=0) @@ -169,7 +166,11 @@ def run(): elif options.clear: from build.project import update_version print "Version:" + str(update_version()) - + import webnotes.utils.cache + webnotes.conn.begin() + webnotes.utils.cache.clear() + webnotes.conn.commit() + # code replace elif options.replace: replace_code('.', options.replace[0], options.replace[1], options.replace[2]) @@ -245,14 +246,7 @@ def run(): elif options.run_scheduler_event is not None: import webnotes.utils.scheduler print webnotes.utils.scheduler.trigger('execute_' + options.run_scheduler_event) - - elif options.cci is not None: - if options.cci=='all': - webnotes.conn.sql("DELETE FROM __CacheItem") - else: - from webnotes.utils.cache import CacheItem - CacheItem(options.cci).clear() - + elif options.sync_all is not None: import webnotes.model.sync webnotes.model.sync.sync_all(options.force or 0)