/**
  * cache_event function
  *
  * Creates a new entry in the cache table for each date that the event appears
  * (and does not already have an explicit RECURRENCE-ID instance, given its
  * iCalendar UID).
  *
  * @param Ai1ec_Event $event Event to generate cache table for
  *
  * @return void
  **/
 public function cache_event(Ai1ec_Event &$event)
 {
     global $wpdb;
     // Convert event timestamps to local for correct calculations of
     // recurrence. Need to also remove PHP timezone offset for each date for
     // SG_iCal to calculate correct recurring instances.
     $event->start = $this->gmt_to_local($event->start) - date('Z', $event->start);
     $event->end = $this->gmt_to_local($event->end) - date('Z', $event->end);
     $evs = array();
     $e = array('post_id' => $event->post_id, 'start' => $event->start, 'end' => $event->end);
     $duration = $event->getDuration();
     // Timestamp of today date + 3 years (94608000 seconds)
     $tif = Ai1ec_Time_Utility::current_time(true) + 94608000;
     // Always cache initial instance
     $evs[] = $e;
     $_start = $event->start;
     $_end = $event->end;
     if ($event->recurrence_rules) {
         $start = $event->start;
         $wdate = $startdate = iCalUtilityFunctions::_timestamp2date($_start, 6);
         $enddate = iCalUtilityFunctions::_timestamp2date($tif, 6);
         $exclude_dates = array();
         $recurrence_dates = array();
         if ($event->exception_rules) {
             // creat an array for the rules
             $exception_rules = $this->build_recurrence_rules_array($event->exception_rules);
             $exception_rules = iCalUtilityFunctions::_setRexrule($exception_rules);
             $result = array();
             // The first array is the result and it is passed by reference
             iCalUtilityFunctions::_recur2date($exclude_dates, $exception_rules, $wdate, $startdate, $enddate);
         }
         $recurrence_rules = $this->build_recurrence_rules_array($event->recurrence_rules);
         $recurrence_rules = iCalUtilityFunctions::_setRexrule($recurrence_rules);
         iCalUtilityFunctions::_recur2date($recurrence_dates, $recurrence_rules, $wdate, $startdate, $enddate);
         // Add the instances
         foreach ($recurrence_dates as $date => $bool) {
             // The arrays are in the form timestamp => true so an isset call is what we need
             if (isset($exclude_dates[$date])) {
                 continue;
             }
             $e['start'] = $date;
             $e['end'] = $date + $duration;
             $excluded = false;
             // Check if exception dates match this occurence
             if ($event->exception_dates) {
                 if ($this->date_match_exdates($date, $event->exception_dates)) {
                     $excluded = true;
                 }
             }
             // Add event only if it is not excluded
             if ($excluded == false) {
                 $evs[] = $e;
             }
         }
     }
     // Make entries unique (sometimes recurrence generator creates duplicates?)
     $evs_unique = array();
     foreach ($evs as $ev) {
         $evs_unique[md5(serialize($ev))] = $ev;
     }
     foreach ($evs_unique as $e) {
         // Find out if this event instance is already accounted for by an
         // overriding 'RECURRENCE-ID' of the same iCalendar feed (by comparing the
         // UID, start date, recurrence). If so, then do not create duplicate
         // instance of event.
         $start = $this->local_to_gmt($e['start']) - date('Z', $e['start']);
         $matching_event_id = $event->ical_uid ? $this->get_matching_event_id($event->ical_uid, $event->ical_feed_url, $start, false, $event->post_id) : NULL;
         // If no other instance was found
         if (NULL === $matching_event_id) {
             $start = getdate($e['start']);
             $end = getdate($e['end']);
             $this->insert_event_in_cache_table($e);
         }
     }
     return Ai1ec_Events_List_Helper::get_instance()->clean_post_cache($event->post_id);
 }