Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

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

Clearing cached data for specific DataObjectSet


Reply

4 Posts   795 Views

Avatar
BlueScreen

15 March 2011 at 9:27am Community Member, 36 Posts

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

Avatar
BlueScreen

16 March 2011 at 8:57am Community Member, 36 Posts

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

Avatar
martimiz

16 March 2011 at 9:54am (Last edited: 16 March 2011 9:55am), Forum Moderator, 1091 Posts

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

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

Avatar
BlueScreen

16 March 2011 at 11:20am Community Member, 36 Posts

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