IEventService.GetEvents - tag filters seem to be caching results

IEventService.GetEvents - tag filters seem to be caching results

This question is not answered

We have a custom endpoint that wraps the IEventService and calls into "GetEvents", which is the 4th overload to this method, accepting calendarId, filterTags, logicallyOrTags, pageSize, pageIndex.

When integration testing this via the REST console, I have 3 events each with different tags. Let's say Event 1 is tagged "X". Event 2 is tagged "Y". Event 3 is tagged "Z".

When I query this endpoint for all events with tag "X", it returns Event 1 (expected). When I query this endpoint for all events with tag "Y", it sill returns Event 1 (unexpected), unless I vary the "LogicallyOrTags" boolean parameter to this method on each method invocation or rest request.

It seems that the service call's response is somehow cached internally.

Or, could it be that the IEventService IOC binding in the CalendarModule.config is in "singleton" scope? (I wouldn't think this b/c pretty much all the bindings appear to be singleton scoped)

This is the custom endpoint code:

public CalendarEventListResponse List(CalendarEventListRequest request)
        {
            CalendarEventListResponse response = new CalendarEventListResponse(request);
            PagedList<CalendarEvent> events = new PagedList<CalendarEvent>();
            try
            {
                IEventService svc = Telligent.Common.Services.Get<IEventService>();
                PagedSet<Event> items = new PagedSet<Event>();
                if (!string.IsNullOrEmpty(request.TagString))
                {
                    string[] tags = request.TagString.Split(',');                    
                    items = svc.GetEvents(request.CalendarId, tags, request.LogicallyOrTags, Convert.ToInt32(request.PageIndex), Convert.ToInt32(request.PageSize));
                }
                else
                {
                    EventQuery q = new EventQuery(new User());
                    q.QueryType = EventQueryType.NotSet;
                    q.CalendarId = request.CalendarId;
                    q.CalendarReferenceId = request.CalendarId;
                    q.PageIndex = 0;
                    items = svc.GetEvents(q);
                }
                foreach (Event evt in items)
                {
                    CalendarEvent commEvt = Mapper.Map<EventCalendarEvent>(evt);
                    commEvt.EventTags = string.Empty;
                    foreach (string tagstr in evt.Tags)
                    {
                        commEvt.EventTags += tagstr + ",";
                    }
                    if (commEvt.EventTags.Trim().EndsWith(","))
                    {
                        commEvt.EventTags = commEvt.EventTags.Remove(commEvt.EventTags.Length - 1);
                    }
                    events.Add(commEvt);
                }
            }
            catch (Exception ex)
            {
                response.Errors.Add(ex.Message);
            }
 
            if (events != null)
            {
                response.CalendarEvents = events;
            }
            else
            {
                response.Errors.Add("Unable to retrieve CalendarEvents");
            }
 
            return response;
        }
All Replies
  • i noticed that the tagged content list widget in TC6 has the same issue with these events. when you click the tag of one of the events, it shows the correct one. then you go to a different event and click it's different tag than the first event, and it shows you the first event, not the second.

  • after decompiling the EventService in ILSpy I see that the code is pulling a paged set of Events from the cache. Is there a way to clear the cache before each request in our custom endpoint? It looks like all those cache clearing methods are private and inaccessible unless you update an event first as a workaround...

    here's your code:

    public PagedSet<Event> GetEvents(int calendarId, string[] filterTags, bool logicallyOrTags, int pageIndex, int pageSize)
    		{
    			EventQuery eventQuery = new EventQuery(null);
    			eventQuery.CalendarId = calendarId;
    			eventQuery.PageIndex = pageIndex;
    			eventQuery.PageSize = pageSize;
    			eventQuery.ExtendedParameters["filterTags"] = ((filterTags == null) ? "" : filterTags.ToString());
    			eventQuery.ExtendedParameters["logicallyOrTags"] = logicallyOrTags.ToString();
    			PagedSet<Event> pagedSet = this.GetPagedSetOfEventsFromCache(eventQuery);
    			if (pagedSet == null)
    			{
    				pagedSet = this.Events.GetEvents(calendarId, filterTags, logicallyOrTags, pageIndex, pageSize);
    				if (pagedSet != null)
    				{
    					this.PushPagedSetOfEventsToCache(pagedSet, eventQuery);
    				}
    			}
    			return pagedSet;
    		}
  • wow. doing the following actually works and clears the cache after each request so the next request doesn't pull from the cache.

    private const string EVENT_CACHE_KEY = "CALENDAR_PK_EVENT-QUERY:";
     
            public CalendarEventController()
            {
                //can use this for dependency injection of services
                Mapper.CreateMap<EventCalendarEvent>();
            }
     
            public CalendarEventListResponse List(CalendarEventListRequest request)
            {
                CalendarEventListResponse response = new CalendarEventListResponse(request);
                PagedList<CalendarEvent> events = new PagedList<CalendarEvent>();
                try
                {
                    IEventService svc = Telligent.Common.Services.Get<IEventService>();
                    PagedSet<Event> items = new PagedSet<Event>();
                    if (!string.IsNullOrEmpty(request.TagString))
                    {
                        string[] tags = request.TagString.Split(',');                    
                        items = svc.GetEvents(request.CalendarId, tags, request.LogicallyOrTags, Convert.ToInt32(request.PageIndex), Convert.ToInt32(request.PageSize));
                        ICacheService cache = Telligent.Common.Services.Get<ICacheService>();
                        cache.Clear(Telligent.Caching.CacheScope.Context | Telligent.Caching.CacheScope.Process);
                    }
                    else
                    {
                        EventQuery q = new EventQuery(null);
                        q.QueryType = EventQueryType.NotSet;
                        q.CalendarId = request.CalendarId;
                        //q.CalendarReferenceId = request.CalendarId;
                        if(request.PageSize.HasValue)
                            q.PageSize = request.PageSize.Value;
     
                        if (request.PageIndex.HasValue)
                            q.PageIndex = request.PageIndex.Value;
                        
                        items = svc.GetEvents(q);
                        ICacheService cache = Telligent.Common.Services.Get<ICacheService>();
                        cache.Remove(string.Format("{0}{1}", EVENT_CACHE_KEY, q.GetKey()), Telligent.Caching.CacheScope.Context | Telligent.Caching.CacheScope.Process);
                    }
                    foreach (Event evt in items)
                    {
                        CalendarEvent commEvt = Mapper.Map<EventCalendarEvent>(evt);
                        commEvt.EventTags = string.Empty;
                        foreach (string tagstr in evt.Tags)
                        {
                            commEvt.EventTags += tagstr + ",";
                        }
                        if (commEvt.EventTags.Trim().EndsWith(","))
                        {
                            commEvt.EventTags = commEvt.EventTags.Remove(commEvt.EventTags.Length - 1);
                        }
                        events.Add(commEvt);
                    }
                }
                catch (Exception ex)
                {
                    response.Errors.Add(ex.Message);
                }
     
                if (events != null)
                {
                    response.CalendarEvents = events;
                }
                else
                {
                    response.Errors.Add("Unable to retrieve CalendarEvents");
                }
     
                return response;
            }