"Most recent" RoomQuery caching out of sync with RoomBase.LastChangedTopic.Created

Vote:
 

When executing the following query:

var roomQuery = new RoomQuery
            {
                Forum =
                    new ForumCriterion
                    {
                        ID = new IntegerCriterion { Value = Properties.Settings.Default.RootForumId }
                    }
            };

roomQuery.LastChangedTopic = new TopicCriterion {Created = new DateTimeCriterion()};
                    roomQuery.OrderBy.Add(new CriterionSortOrder(roomQuery.LastChangedTopic.Created, SortingDirection.Descending));

var rooms = ForumHandler.Instance.GetQueryResult(roomQuery, page, pageSize, out totalItems);

and then rendering the results in a template (in my case a Razor view):

@foreach (var room in Model.Rooms)
{
    

@room.Header.FormatOrEncodeContentText() (@room.NumReplies)

Last updated @room.FormatLatestPostDate()

}

it appears that the results of the query are cached (for an indeterminate amount of time) but the derived value for "Date of Last Post" is not, e.g.

public static string FormatLatestPostDate(this RoomBase room)
        {
            if (room.LastChangedTopic != null)
            {
                var last = room.LastChangedTopic.LastReply;
                if (last != null)
                {
                    return last.Changed
                        ? last.Modified.FormatTimeSince()
                        : last.Created.FormatTimeSince();
                }

                return room.LastChangedTopic.Changed
                    ? room.LastChangedTopic.Modified.FormatTimeSince()
                    : room.LastChangedTopic.Created.FormatTimeSince();
            }

            return string.Empty;
        }

(code modified from Rooms.ascx.cs GetDateOfLatestPost(RoomBase room) method).

The result is that after a topic update, my displayed list shows the rooms in the same order as before the update, yet the "Last Updated" field IS up-to-date, meaning my list looks out of order.

So the question is, is there any way to:

1. Flush the cache for my RoomQuery manually?

2. Cache the LastChangedTopic with a dependency on the RoomQuery cache key?

#90893
Sep 22, 2014 7:40
Vote:
 

FYI this is for Relate+ 7.5

#90894
Sep 22, 2014 7:44
Vote:
 

Regarding alternative 1: this can be done using EPiServer.Common.Queries.QueryHandler.Instance.RemoveQueryResultCache(myquery);

#91326
Oct 02, 2014 15:52
Vote:
 

I have kludged my way around this using the RemoveQueryResultCache suggestion. I incorporated this into a IInitializationModule:

[InitializableModule]
    public class ForumQueryCacheInitialization : IInitializableModule
    {
        public static RoomQuery RecentRoomsQuery;

        public void Initialize(InitializationEngine context)
        {
            ForumHandler.Instance.TopicAdded += (sender, args) =>
            {
                if (RecentRoomsQuery != null)
                {
                    QueryHandler.Instance.RemoveQueryResultCache(RecentRoomsQuery);
                }
            };
        }

        public void Uninitialize(InitializationEngine context)
        {
            
        }

        public void Preload(string[] parameters)
        {
            
        }
    }

Then in the code actually executing the query I ensure that ForumQueryCacheInitialization.RecentRoomsQuery is updated everytime it is queried, e.g.

// KLUDGE: Force the cache to empty for RecentRoomQuery
ForumQueryCacheInitialization.RecentRoomsQuery = roomQuery;

It seems a bit ugly but I am trying to get a clean fix via EPiServer support.

#91582
Oct 08, 2014 23:55
Vote:
 

Hi Lance - did you get anywhere with EPiServer support?  I'm having to implement the same fudge for a very similar issue:

I create the topic, if I try to query for it, it's not retured, remove the query result from the cache, query again and it's returned.

#118275
Edited, Mar 03, 2015 18:37
Vote:
 
<p>Hi Neil,</p> <p>Unfortunately no. My workaround ended up being the best solution for us. EPiServer support did try to help but they didn't reply to my last message and my deadline was looming so I did not chase it up.</p>
#118285
Mar 03, 2015 20:49
Vote:
 

Thanks Lance - sounds familiar!

#118308
Mar 04, 2015 10:08
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.