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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Clearing cached data for specific DataObjectSet


Go to End


4 Posts   1251 Views

Avatar
BlueScreen

Community Member, 36 Posts

15 March 2011 at 9:27am

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

Community Member, 36 Posts

16 March 2011 at 8:57am

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

Avatar
martimiz

Forum Moderator, 1391 Posts

16 March 2011 at 9:54am

Edited: 16/03/2011 9:55am

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

Community Member, 36 Posts

16 March 2011 at 11:20am

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