/**
  * Creates a new request, sends and receives the data, uses caching if defined by the user.
  * @param string $uri The uri this request is sent to.
  * @param string $method The method (GET,PUT,POST,DELETE)
  * @param array $customHeader A customHeader to be sent
  * @param array $data The data to be sent as array
  * @return EActiveResourceResponse The response object
  */
 public function sendRequest($uri, $method, $data = null, $customHeader = null, $contentType = 'application/json', $acceptType = 'application/json')
 {
     ///LOOK FOR CACHED RESPONSES FIRST
     if ($this->queryCachingCount > 0 && $this->queryCachingDuration > 0 && $this->queryCacheID !== false && ($cache = Yii::app()->getComponent($this->queryCacheID)) !== null) {
         $this->queryCachingCount--;
         $cacheKey = 'yii:eactiveresourcerequest:' . $uri . ':' . $method . ':' . $this->recursiveImplode('-', $customHeader);
         $cacheKey .= ':' . $this->recursiveImplode('#', $data);
         if (($result = $cache->get($cacheKey)) !== false) {
             Yii::trace('Respone found in cache', 'ext.EActiveResource.EActiveResourceConnection');
             return $result;
         }
     }
     $request = new EActiveResourceRequest();
     $request->setUri($uri);
     $request->setMethod($method);
     $request->setData($data);
     $request->setContentType($contentType);
     $request->setAcceptType($acceptType);
     $request->setCustomHeader($customHeader);
     $response = $request->run();
     //CACHE RESULT IF CACHE IS SET
     if (isset($cache, $cacheKey)) {
         $cache->set($cacheKey, $response, $this->queryCachingDuration, $this->queryCachingDependency);
     }
     return $response;
 }
 /**
  * Perform a query (mainly used by the finder methods). Only queries allow caching and fire a beforeFind
  * event
  * @param string $route The route to be sued by the query
  * @param string $method The method to be used (defaults to GET)
  * @param array $params Additional params for the query
  * @param array $data Optional data to be sent
  * @return EActiveResourceResponse The response 
  */
 public function query($route, $method = 'GET', $params = array(), $data = null)
 {
     $this->beforeFind();
     $uri = $this->buildUri($route);
     if (!empty($params)) {
         $uri = $uri . '?' . http_build_query($params);
     }
     $request = new EActiveResourceRequest();
     $request->setUri($uri);
     $request->setMethod($method);
     $request->setData($data);
     return $this->getConnection()->query($request);
 }