Should memoize the object to avoid multiple query if get_object is used many times in the view
348124
def get_object(self, *args, **kwargs):
        
        self.category_instance = get_object_or_404(Category, slug=self.kwargs['category_slug'])
        return get_object_or_404(Post, thread__id=self.kwargs['thread_id'], thread__category=self.category_instance, pk=self.kwargs['post_id'])
219981
def memoize(function):
    
    cache = {}
    @functools.wraps(function)
    def _memoize(*args):
        if args in cache:
            return cache[args]
        result = function(*args)
        cache[args] = result
        return result
    return function
129471
def cached_getter(func):
  """"""
  @wraps(func)
  def wrapper(self):
    attribute = f'_{func.__name__}'
    value = getattr(self, attribute, None)
    if value is None:
      value = func(self)
      setattr(self, attribute, value)
    return value
  return wrapper
741309
def delete_objects_associated_with_a_record(self, name, view, delete_list):
        """"""
        search_objects = {}
        if 'record:cname' in delete_list:
            search_objects['record:cname'] = 'canonical'
        if 'record:txt' in delete_list:
            search_objects['record:txt'] = 'name'

        if not search_objects:
            return

        for obj_type, search_type in search_objects.items():
            payload = {'view': view,
                       search_type: name}
            ib_objs = self.connector.get_object(obj_type, payload)
            if ib_objs:
                for ib_obj in ib_objs:
                    self.delete_object_by_ref(ib_obj['_ref'])
603094
def store_memory_object(self, mo, overwrite=True):
        

        for p in self._containing_pages_mo(mo):
            self._apply_object_to_page(p, mo, overwrite=overwrite)

        self._update_range_mappings(mo.base, mo.object, mo.length)
399225
def get(self, *args, **kwargs):
        
        clone = self.filter(*args, **kwargs)

        if self.query.can_filter():
            clone = clone.order_by()

        num = len(clone)

        if num == 1:
            return clone._result_cache[0]
        if not num:
            raise self.resource.DoesNotExist(
                "%s matching query does not exist. "
                "Lookup parameters were %s" %
                (self.resource._meta.resource_name, kwargs))

        raise self.resource.MultipleObjectsReturned(
            "get() returned more than one %s -- it returned %s! "
            "Lookup parameters were %s" %
            (self.resource._meta.resource_name, num, kwargs))
1136232
def _getCachedValue(obj, relicFunc, resultType):
    
    # If the value has not been previously cached, fetch 
    if not obj.cached:
        obj.cached = resultType()
        relicFunc(byref(obj.cached))
    return obj.cached
690245
def memoize(func):
    '''
    
    '''
    cache = {}

    @wraps(func)
    def _memoize(*args, **kwargs):
        str_args = []
        for arg in args:
            if not isinstance(arg, six.string_types):
                str_args.append(six.text_type(arg))
            else:
                str_args.append(arg)

        args_ = ','.join(list(str_args) + ['{0}={1}'.format(k, kwargs[k]) for k in sorted(kwargs)])
        if args_ not in cache:
            cache[args_] = func(*args, **kwargs)
        return cache[args_]

    return _memoize
1292146
function memoizeCapped(func) {
        var result = memoize(func, function(key) {
            if (cache.size === MAX_MEMOIZE_SIZE) {
                cache.clear();
            }
            return key;
        });

        var cache = result.cache;
        return result;
    }
82355
def memoized(func):
    
    cache = {}
    @wraps(func)
    def memoized_function(*args):
        """The decorated function.
        """
        try:
            return cache[args]
        except KeyError:
            value = func(*args)
            try:
                cache[args] = value
            except MemoryError:
                cache.clear()
                gc.collect()
            return value
    return memoized_function
571987
private void cacheUniqueSelectRef(Object object, MappedStatement mt, String cacheKey) {
		Collection<QueryMethodCache> mcs = queryCacheMethods.get(mt.getId().substring(0, mt.getId().lastIndexOf(SPLIT_PONIT))).values();
		outter:for (QueryMethodCache methodCache : mcs) {
			if(methodCache.isPk || methodCache.groupRalated)continue;
			try {	
				Object[] cacheFieldValues = new Object[methodCache.fieldNames.length];
				for (int i = 0; i < cacheFieldValues.length; i++) {
					if(methodCache.fieldNames[i] == null)break outter;
					cacheFieldValues[i] = ReflectUtils.getObjectValue(object, methodCache.fieldNames[i]);
					if(cacheFieldValues[i] == null)continue outter;
				}
				String fieldCacheKey = genarateQueryCacheKey(methodCache.keyPattern , cacheFieldValues);
				
				cacheFieldRefKey(fieldCacheKey,cacheKey, methodCache.getExpire());
				if(logger.isDebugEnabled())logger.debug("_autocache_ method[{}] add ref cacheKey:{}",mt.getId(),fieldCacheKey);
			} catch (Exception e) {
				logger.warn("cacheUniqueSelectRef:"+cacheKey,e);
			}
		}
	}
1105850
def _memoize(self, name, getter, *args, **kwargs):
        
        field = "custom_m_" + name
        cached = self.fetch(field)
        if cached:
            value = cached
        else:
            value = getter(*args, **kwargs)
            self._make_it_so("caching %s=%r for" % (name, value,), ["custom.set"], field[7:], value)
            self._fields[field] = value
        return value
1190626
private void cacheLinkedObject(String owningObjID,
                                   String linkFieldName,
                                   DBObject linkedObject) {
        // Find or create map for the owning object.
        Map<String, Map<String, DBObject>> objMap = m_linkedObjectMap.get(owningObjID);
        if (objMap == null) {
            objMap = new HashMap<String, Map<String, DBObject>>();
            m_linkedObjectMap.put(owningObjID, objMap);
        }
        
        // Find or create map for the link field.
        Map<String, DBObject> linkMap = objMap.get(linkFieldName);
        if (linkMap == null) {
            linkMap = new HashMap<String, DBObject>();
            objMap.put(linkFieldName, linkMap);
        }
        
        // Add the object to the link map.
        linkMap.put(linkedObject.getObjectID(), linkedObject);
    }
1333055
function memoized() {
          if (!lastArguments) {
              lastResult = projectionFn.apply(null, arguments);
              lastArguments = arguments;
              return lastResult;
          }
          if (!isArgumentsChanged(arguments, lastArguments, isArgumentsEqual)) {
              return lastResult;
          }
          lastArguments = arguments;
          var newResult = projectionFn.apply(null, arguments);
          if (isResultEqual(lastResult, newResult)) {
              return lastResult;
          }
          lastResult = newResult;
          return newResult;
      }
180218
def memoize(obj):
    
    cache = obj.cache = {}

    @functools.wraps(obj)
    def memoizer(*args, **kwargs):
        key = str(args) + str(kwargs)
        if key not in cache:
            cache[key] = obj(*args, **kwargs)
        # only keep the most recent 100 entries
        if len(cache) > 100:
            cache.popitem(last=False)
        return cache[key]
    return memoizer
493859
def memoize(f):
    
    cache = {}

    @wraps(f)
    def inner(arg):
        if arg not in cache:
            cache[arg] = f(arg)
        return cache[arg]
    return inner
1156187
def memoize(fn):
    ''''''

    cache = {}

    @wraps(fn)
    def wrapped_function(*args):
        if args in cache:
            return cache[args]

        else:
            result = fn(*args)
            cache[args] = result
            return result

    return wrapped_function