00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 import copy
00029
00030 class AbstractCache:
00031 def exists( self, obj, method, *args ):
00032 pass
00033 def get( self, obj, method, *args ):
00034 pass
00035
00036 class ViewCache(AbstractCache):
00037 exceptions = []
00038
00039 def __init__(self):
00040 self.cache = {}
00041
00042 def exists(self, obj, method, *args):
00043 if method != 'execute' or len(args) < 2 or args[1] != 'fields_view_get':
00044 return False
00045 return (obj, method, str(args)) in self.cache
00046
00047 def get(self, obj, method, *args):
00048 return copy.deepcopy( self.cache[(obj, method, str(args))] )
00049
00050 def add(self, value, obj, method, *args):
00051 if method != 'execute' or len(args) < 2 or args[1] != 'fields_view_get':
00052 return
00053
00054 if args[0] in ViewCache.exceptions:
00055 return False
00056 self.cache[(obj,method,str(args))] = copy.deepcopy( value )
00057
00058 def clear(self):
00059 self.cache = {}
00060
00061 class ActionViewCache(AbstractCache):
00062 exceptions = []
00063
00064 def __init__(self):
00065 self.cache = {}
00066
00067 def exists(self, obj, method, *args):
00068 if method == 'execute' and len(args) >= 3 and args[1] == 'search' and ( args[2] == [('id','in',[])] or args[2] == [['id','in',[]]] ):
00069
00070
00071
00072 return True
00073 if method == 'execute' and len(args) >= 2 and args[1] == 'fields_view_get':
00074 return (obj, method, str(args)) in self.cache
00075 elif method == 'execute' and len(args) >= 2 and args[0] == 'ir.values' and args[1] == 'get':
00076 return (obj, method, str(args)) in self.cache
00077 elif obj == '/fulltextsearch' and method == 'indexedModels':
00078 return (obj, method, str(args)) in self.cache
00079 else:
00080 return False
00081
00082 def get(self, obj, method, *args):
00083 if method == 'execute' and len(args) >= 3 and args[1] == 'search' and ( args[2] == [('id','in',[])] or args[2] == [['id','in',[]]] ):
00084
00085
00086
00087 return []
00088 return copy.deepcopy( self.cache[(obj, method, str(args))] )
00089
00090 def add(self, value, obj, method, *args):
00091
00092 if method == 'execute' and len(args) >= 2 and args[1] == 'fields_view_get':
00093
00094 if args[0] in ViewCache.exceptions:
00095 return
00096 self.cache[(obj,method,str(args))] = copy.deepcopy( value )
00097 elif method == 'execute' and len(args) >= 2 and args[0] == 'ir.values' and args[1] == 'get':
00098 self.cache[(obj,method,str(args))] = copy.deepcopy( value )
00099 elif obj == '/fulltextsearch' and method == 'indexedModels':
00100 self.cache[(obj,method,str(args))] = copy.deepcopy( value )
00101
00102 def clear(self):
00103 self.cache = {}
00104