Jump to:

23491 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Clearing cached data for specific DataObjectSet

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 787 Views
  • BlueScreen
    Avatar
    Community Member
    36 Posts

    Clearing cached data for specific DataObjectSet Link to this post

    Hi, So I have an application that displays a list of bookings. These bookings are called from an API and added to a DataObjectSet before being passed to the HTML. The bookings are only displayed if their status is "active".

    The DataObjectSet looks like this:

    $Res = new DataObjectSet();      
             foreach($this->Reservations as $current) {
                if(!empty($current->Status)) {
                   if($current->Status == "Active") {
                      // To retrieve the date in a format that Silverstripe
                      // will be able to play with, we need to convert it to a date object.
                      $Date = new Date('Date');
                      $Date->setValue((string)$current->DateMade);
                      $dateMade = $Date->Format('D, j M Y');
                      // Put info from RSS into an Array, then push into $result
                      $Res->push(new ArrayData(array(
                       'ItineraryRef' => (int)$current->ItineraryRef,
                       'Type' => (string)$current->Type,
                       'DateMade' => (string)$dateMade,
                       'DateCreated' => (string)$current->DateMade,
                       'URLDate' => (string)$current->DateMade,
                       'PaxCount' => (int)$current->PaxCount,
                       'Description' => (string)$current->Description,
                       'Status' => (string)$current->Status,
                       'DateAccessed' => $Date,
                      )));
                      $i++;
                   }
                }


    Next to each booking is a link which will cancel the booking, again this is done by calling another API that immediately sets the status of the booking to "CANCELLED" so that they do not appear in the list.

    I want cancelled bookings to disappear from the list the next time the page refreshes but even though the bookings definitely get cancelled in the back-end; on the front-end, the cancelled bookings always remain 'active' until the user logs off and logs back in again.

    I think the problem is that Silverstripe is not calling new data from the API after the page refreshes, it retrieves old data from the DataObjectSet and the information in the DataObjectSet remains intact until the user logs off and the session is destroyed.

    So my question is, how do you tell silverstripe to delete any cached information for a specific DataObjectSet or to not cache DataObjects at all?

    I tried DataObject::destroy() and $Res->destroy() but that kills the users session too

    Any alternative ideas are welcome too. Thanks

  • BlueScreen
    Avatar
    Community Member
    36 Posts

    Re: Clearing cached data for specific DataObjectSet Link to this post

    So...no response because there is no answer? Or because the answer is obvious? Which one?

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: Clearing cached data for specific DataObjectSet Link to this post

    There is, for instance, the DataObject->flushCache() method. Check the DataObject API here:

    http://api.silverstripe.org/2.4/sapphire/model/DataObject.html#methodflushCache

  • BlueScreen
    Avatar
    Community Member
    36 Posts

    Re: Clearing cached data for specific DataObjectSet Link to this post

    Unfortunately that function does not exist for DataObjectSets, unless there is a way to hack that same functionality in there.

    I also tried DataObject::FlushCache(true) but that appeared to have no influence. The list still reloads with deleted bookings as if nothing happened

    787 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.