Example #1
0
 /**
  * Process a request (with cache support)
  *
  * @param $url
  * @return array|false|mixed
  */
 private function process_request($url)
 {
     debugging("Processing request: {$url}");
     // cache key
     $key = urlencode($url);
     // check whether the current path has been already selected:
     // if the 'lastPath' is equal to 'path' then the corresponding
     // cached value will be removed !!!
     if (strcmp($this->requests->get(self::OMERO_LAST_QUERY_KEY), $url) === 0) {
         $this->requests->delete($key);
         debugging("Cleaning cache: " . "{$url} -- " . $key);
     }
     // store the last query URL
     $this->requests->set(self::OMERO_LAST_QUERY_KEY, $url);
     // check whether the request is in cache and process it otherwise
     $response = $this->requests->get($key);
     if (!$response) {
         debugging("Getting data from the SERVER: {$url}");
         $response = $this->omero->process_request($url, true, $this->access_key, $this->access_secret);
         $this->requests->set($key, $response);
         debugging("RESPONSE IS OBJECT: " . (is_object($response) ? "OK" : "NO"));
     } else {
         debugging("Getting data from the CACHE: {$url}");
     }
     return $response;
 }
Example #2
0
 /**
  * Check that this cache instance is tracking the current user.
  */
 protected function check_tracked_user()
 {
     if (isset($_SESSION['USER']->id) && $_SESSION['USER']->id !== null) {
         // Get the id of the current user.
         $new = $_SESSION['USER']->id;
     } else {
         // No user set up yet.
         $new = 0;
     }
     if ($new !== self::$loadeduserid) {
         // The current user doesn't match the tracked userid for this request.
         if (!is_null(self::$loadeduserid)) {
             // Purge the data we have for the old user.
             // This way we don't bloat the session.
             $this->purge();
             // Update the session id just in case!
             $this->set_session_id();
         }
         self::$loadeduserid = $new;
         $this->currentuserid = $new;
     } else {
         if ($new !== $this->currentuserid) {
             // The current user matches the loaded user but not the user last used by this cache.
             $this->purge_current_user();
             $this->currentuserid = $new;
             // Update the session id just in case!
             $this->set_session_id();
         }
     }
 }