public static function start(IRelatedObject $object, KalturaDetachedResponseProfile $responseProfile) { if (self::$cachedObject) { KalturaLog::debug("Object [" . get_class(self::$cachedObject) . "][" . self::$cachedObject->getId() . "] still caching"); return null; } KalturaLog::debug("Start " . get_class($object) . " [" . $object->getId() . "]"); $responseProfileKey = $responseProfile->getKey(); $setResponseProfile = self::$responseProfileKey != $responseProfileKey; $responseProfileCacheKey = self::getResponseProfileCacheKey($responseProfileKey, $object->getPartnerId()); if (self::get($responseProfileCacheKey)) { $key = self::getObjectSpecificCacheKey($object, $responseProfileKey); $invalidationKeys = array(self::getObjectKey($object), self::getRelatedObjectKey($object, $responseProfileKey)); $value = self::get($key, $invalidationKeys); if ($value) { $apiObject = unserialize($value->apiObject); KalturaLog::debug("Returned object: [" . print_r($apiObject, true) . "]"); if ($apiObject instanceof KalturaObject) { return $apiObject->relatedObjects; } } KalturaLog::debug("Object [" . get_class($object) . "][" . $object->getId() . "] - response profile found but object not cached"); } else { KalturaLog::debug("Object [" . get_class($object) . "][" . $object->getId() . "] - response profile not found"); } self::$cachedObject = $object; self::$responseProfileKey = $responseProfileKey; if ($setResponseProfile) { self::set($responseProfileCacheKey, serialize($responseProfile)); } }
/** * @param KalturaObject $apiObject * @param IRelatedObject $object * @param KalturaDetachedResponseProfile $responseProfile * @return boolean */ public static function start(KalturaObject $apiObject, IRelatedObject $object, KalturaDetachedResponseProfile $responseProfile) { if (self::$cachedObject) { KalturaLog::debug("Object [" . get_class(self::$cachedObject) . "][" . self::$cachedObject->getId() . "] still caching"); return false; } $responseProfileKey = $responseProfile->getKey(); $key = self::getObjectSpecificCacheKey($object, $responseProfileKey); $responseProfileCacheKey = self::getResponseProfileCacheKey($responseProfileKey, $object->getPartnerId()); list($value, $responseProfileCache) = self::get(array($key, $responseProfileCacheKey)); $invalidationKeys = array(self::getObjectKey($object), self::getRelatedObjectKey($object, $responseProfileKey)); if ($value && self::areKeysValid($invalidationKeys, $value->{self::CACHE_VALUE_TIME})) { $cachedApiObject = unserialize($value->apiObject); if ($cachedApiObject instanceof KalturaObject) { $properties = get_object_vars($cachedApiObject); foreach ($properties as $propertyName => $propertyValue) { $apiObject->{$propertyName} = $propertyValue; } return true; } KalturaLog::err("Object [" . get_class($object) . "][" . $object->getId() . "] - invalid object cached"); } KalturaLog::debug("Start " . get_class($object) . " [" . $object->getId() . "]"); if (self::$responseProfileKey != $responseProfileKey && !$responseProfileCache) { self::set($responseProfileCacheKey, array('responseProfile' => serialize($responseProfile))); } self::$cachedObject = $object; self::$responseProfileKey = $responseProfileKey; return false; }