TODO cache result
5444
private static String calcClassSign(String name) {
        try {
            Class<?> clazz = Class.forName(name);

            ByteArrayOutputStream result = new ByteArrayOutputStream();
            ObjectOutputStream outputStream = new ObjectOutputStream(result);
            outputStream.writeObject(clazz);
            outputStream.close();

            MessageDigest crypt = MessageDigest.getInstance("SHA-1");
            crypt.reset();
            crypt.update(result.toByteArray());

            return new BigInteger(1, crypt.digest()).toString(16);
        } catch (Exception e) {
            throw new IllegalStateException("Can't calculate sign of " + name, e);
        }
    }
262969
function ExecutionCache() {
  var cache = {};

  function getKey(query) {
    return query.queryKey + '(' + JSON.stringify(query.queryParams) + ')'
  }

  function get(query) {
    return cache[getKey(query)]
  }

  this.execute = function (query) {
    var query = _.cloneDeep(query);
    var execution = get(query);
    if (execution) {
      var requestedKeys = _.keys(query.shape);
      if (_.intersection(_.keys(execution.shape), requestedKeys).length != requestedKeys.length) {
        // TODO we probably should also merge the nested shape
        var newShape = _.assign(execution.shape, query.shape);
        query.shape = newShape;
        execution = {
          shape: newShape,
          promise: getHandler(query.name, query.queryKey)(query.shape, query.queryParams, query.type)
        }
      }
    } else {
      execution = {
        shape: query.shape,
        promise: getHandler(query.name, query.queryKey)(query.shape, query.queryParams, query.type)
      };
    }
    cache[getKey(query)] = execution;
    return execution;
  };

  this.get = get;
  this.getKey = getKey;
  return this;
}
381806
@Override
	public void cacheResult(CommercePriceEntry commercePriceEntry) {
		entityCache.putResult(CommercePriceEntryModelImpl.ENTITY_CACHE_ENABLED,
			CommercePriceEntryImpl.class, commercePriceEntry.getPrimaryKey(),
			commercePriceEntry);

		finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
			new Object[] {
				commercePriceEntry.getUuid(), commercePriceEntry.getGroupId()
			}, commercePriceEntry);

		finderCache.putResult(FINDER_PATH_FETCH_BY_C_C,
			new Object[] {
				commercePriceEntry.getCommercePriceListId(),
				commercePriceEntry.getCPInstanceUuid()
			}, commercePriceEntry);

		finderCache.putResult(FINDER_PATH_FETCH_BY_C_ERC,
			new Object[] {
				commercePriceEntry.getCompanyId(),
				commercePriceEntry.getExternalReferenceCode()
			}, commercePriceEntry);

		commercePriceEntry.resetOriginalValues();
	}
1349388
function resultModelView (results) {
    // build result with ModelViewEngine
    var viewResultPromise = this.modelViewEngine.result(results)
    // if query has view cache the cache view result
    if (defined(this.cache) && this.cache.view) {
        // and handler to cache result
        viewResultPromise.then(viewResults => this.cache.cacheResults(viewResults))
    }
    // return view result promise - do not wait for cache
    return viewResultPromise
}
969144
@Override
	public void cacheResult(CommercePriceList commercePriceList) {
		entityCache.putResult(CommercePriceListModelImpl.ENTITY_CACHE_ENABLED,
			CommercePriceListImpl.class, commercePriceList.getPrimaryKey(),
			commercePriceList);

		finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
			new Object[] {
				commercePriceList.getUuid(), commercePriceList.getGroupId()
			}, commercePriceList);

		finderCache.putResult(FINDER_PATH_FETCH_BY_PARENTCOMMERCEPRICELISTID,
			new Object[] { commercePriceList.getParentCommercePriceListId() },
			commercePriceList);

		finderCache.putResult(FINDER_PATH_FETCH_BY_C_ERC,
			new Object[] {
				commercePriceList.getCompanyId(),
				commercePriceList.getExternalReferenceCode()
			}, commercePriceList);

		commercePriceList.resetOriginalValues();
	}
297973
@Override
	public void cacheResult(
		List<CPDefinitionVirtualSetting> cpDefinitionVirtualSettings) {
		for (CPDefinitionVirtualSetting cpDefinitionVirtualSetting : cpDefinitionVirtualSettings) {
			if (entityCache.getResult(
						CPDefinitionVirtualSettingModelImpl.ENTITY_CACHE_ENABLED,
						CPDefinitionVirtualSettingImpl.class,
						cpDefinitionVirtualSetting.getPrimaryKey()) == null) {
				cacheResult(cpDefinitionVirtualSetting);
			}
			else {
				cpDefinitionVirtualSetting.resetOriginalValues();
			}
		}
	}
213306
@Override
	public void cacheResult(CPDefinitionLocalization cpDefinitionLocalization) {
		entityCache.putResult(CPDefinitionLocalizationModelImpl.ENTITY_CACHE_ENABLED,
			CPDefinitionLocalizationImpl.class,
			cpDefinitionLocalization.getPrimaryKey(), cpDefinitionLocalization);

		finderCache.putResult(FINDER_PATH_FETCH_BY_CPDEFINITIONID_LANGUAGEID,
			new Object[] {
				cpDefinitionLocalization.getCPDefinitionId(),
				cpDefinitionLocalization.getLanguageId()
			}, cpDefinitionLocalization);

		cpDefinitionLocalization.resetOriginalValues();
	}
966843
@Override
	public void cacheResult(CPOptionValue cpOptionValue) {
		entityCache.putResult(CPOptionValueModelImpl.ENTITY_CACHE_ENABLED,
			CPOptionValueImpl.class, cpOptionValue.getPrimaryKey(),
			cpOptionValue);

		finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
			new Object[] { cpOptionValue.getUuid(), cpOptionValue.getGroupId() },
			cpOptionValue);

		finderCache.putResult(FINDER_PATH_FETCH_BY_C_K,
			new Object[] { cpOptionValue.getCPOptionId(), cpOptionValue.getKey() },
			cpOptionValue);

		finderCache.putResult(FINDER_PATH_FETCH_BY_C_ERC,
			new Object[] {
				cpOptionValue.getCompanyId(),
				cpOptionValue.getExternalReferenceCode()
			}, cpOptionValue);

		cpOptionValue.resetOriginalValues();
	}
255609
function cache(source) {
    var _err = Nil
    var _value = Nil
    var _result = null
    var listeners = null

    return function continuable(callback) {
        if (_err !== Nil || _value !== Nil) {
            callback(_err, _value)
        } else if (listeners) {
            listeners.push(callback)
        } else {
            listeners = [callback]
            _result = source(function (err, value) {
                _err = err
                _value = value

                listeners.forEach(function (l) { l(err, value) })
            })
        }

        return _result
    }
}
349174
@Override
	public void cacheResult(CommerceShippingMethod commerceShippingMethod) {
		entityCache.putResult(CommerceShippingMethodModelImpl.ENTITY_CACHE_ENABLED,
			CommerceShippingMethodImpl.class,
			commerceShippingMethod.getPrimaryKey(), commerceShippingMethod);

		finderCache.putResult(FINDER_PATH_FETCH_BY_G_E,
			new Object[] {
				commerceShippingMethod.getGroupId(),
				commerceShippingMethod.getEngineKey()
			}, commerceShippingMethod);

		commerceShippingMethod.resetOriginalValues();
	}
1044
@Override
	public void cacheResult(CommerceTierPriceEntry commerceTierPriceEntry) {
		entityCache.putResult(CommerceTierPriceEntryModelImpl.ENTITY_CACHE_ENABLED,
			CommerceTierPriceEntryImpl.class,
			commerceTierPriceEntry.getPrimaryKey(), commerceTierPriceEntry);

		finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
			new Object[] {
				commerceTierPriceEntry.getUuid(),
				commerceTierPriceEntry.getGroupId()
			}, commerceTierPriceEntry);

		finderCache.putResult(FINDER_PATH_FETCH_BY_C_M,
			new Object[] {
				commerceTierPriceEntry.getCommercePriceEntryId(),
				commerceTierPriceEntry.getMinQuantity()
			}, commerceTierPriceEntry);

		finderCache.putResult(FINDER_PATH_FETCH_BY_C_ERC,
			new Object[] {
				commerceTierPriceEntry.getCompanyId(),
				commerceTierPriceEntry.getExternalReferenceCode()
			}, commerceTierPriceEntry);

		commerceTierPriceEntry.resetOriginalValues();
	}
663367
function(result, callback) {
            self.cache.put(result, function(err, doc) {
                if (err) return callback(err);
                callback(null, result, doc._id);
            });
        }
306964
function cacheResults (results) {
    // get current max record number
    return this.cache.model.maxRecordNumber({
        session: this.query.session,
    }).then(n => {
        // if state has changed do not cache
        if (n !== this.initialMaxRecordNumber) {
            return
        }
        // JSON encode data to cache
        try {
            var cacheValue = JSON.stringify({
                n: n,
                v: results,
            })
        }
        catch (err) {
            // ignore errors
        }
        // cache result
        if (cacheValue) {
            debug('view:select:collection:set', this.selectCacheKey)
            return this.cache.redis.setAsync(this.selectCacheKey, cacheValue)
        }
    })
}
691485
@Override
	public void cacheResult(CPInstance cpInstance) {
		entityCache.putResult(CPInstanceModelImpl.ENTITY_CACHE_ENABLED,
			CPInstanceImpl.class, cpInstance.getPrimaryKey(), cpInstance);

		finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
			new Object[] { cpInstance.getUuid(), cpInstance.getGroupId() },
			cpInstance);

		finderCache.putResult(FINDER_PATH_FETCH_BY_C_C,
			new Object[] {
				cpInstance.getCPDefinitionId(), cpInstance.getCPInstanceUuid()
			}, cpInstance);

		finderCache.putResult(FINDER_PATH_FETCH_BY_C_S,
			new Object[] { cpInstance.getCPDefinitionId(), cpInstance.getSku() },
			cpInstance);

		finderCache.putResult(FINDER_PATH_FETCH_BY_C_ERC,
			new Object[] {
				cpInstance.getCompanyId(), cpInstance.getExternalReferenceCode()
			}, cpInstance);

		cpInstance.resetOriginalValues();
	}
303004
@Override
	public void cacheResult(CommerceTaxMethod commerceTaxMethod) {
		entityCache.putResult(CommerceTaxMethodModelImpl.ENTITY_CACHE_ENABLED,
			CommerceTaxMethodImpl.class, commerceTaxMethod.getPrimaryKey(),
			commerceTaxMethod);

		finderCache.putResult(FINDER_PATH_FETCH_BY_G_E,
			new Object[] {
				commerceTaxMethod.getGroupId(), commerceTaxMethod.getEngineKey()
			}, commerceTaxMethod);

		commerceTaxMethod.resetOriginalValues();
	}
75073
def result_cached(task_id, wait=0, broker=None):
    
    if not broker:
        broker = get_broker()
    start = time()
    while True:
        r = broker.cache.get('{}:{}'.format(broker.list_key, task_id))
        if r:
            return SignedPackage.loads(r)['result']
        if (time() - start) * 1000 >= wait >= 0:
            break
        sleep(0.01)
713872
@Override
	public void cacheResult(List<CommerceTaxMethod> commerceTaxMethods) {
		for (CommerceTaxMethod commerceTaxMethod : commerceTaxMethods) {
			if (entityCache.getResult(
						CommerceTaxMethodModelImpl.ENTITY_CACHE_ENABLED,
						CommerceTaxMethodImpl.class,
						commerceTaxMethod.getPrimaryKey()) == null) {
				cacheResult(commerceTaxMethod);
			}
			else {
				commerceTaxMethod.resetOriginalValues();
			}
		}
	}