Fullcalendar JSON Feed Caching

∥☆過路亽.° 提交于 2019-12-21 20:38:12

问题


How can I get Fullcalendar to cache events from a JSON feed?

I don't think lazyfetching does what I want it to. It works for a single month. Say I load a month, January, and then change to the day view, the data is cached and does not send an ajax request. But If I change months to Feb and back to Jan, January still reloads.

The author attempted to accomplish the request back in March of 2011 but still fell short, I believe. He lets the browser possibly cache the result of a request, but this is hit or miss and depends on browser settings.

Any ideas? Am I missing something?


回答1:


I would make my own caching object and use it in the events function in the fullcalendar initializer. This method makes use of the "Events as a function" method of getting your event data: http://arshaw.com/fullcalendar/docs/event_data/events_function/

$("#calendar").fullCalendar({

// init options

// go

//here,
    events: function (start, end, callback) {

        //have we already cached this time?
        if (events.eventsCache 
            && events.eventsCache[start.toString + "-" + end.toString]){

                    //if we already have this data, pass it to callback()
            callback(eventsCache[start.toString + "-" + end.toString]);
            return;
        }



        //we haven't gotten this time range (month) yet. get it, and pass it to callback()
        $.get("where_my_events_live.php", function(data){
            if (!events.eventsCache)
                events.eventsCache = {};

            //store your data
            eventsCache[start.toString + "-" + end.toString] = data;
            callback(data);
        });
    },

..r



回答2:


I accomplish this by using backbone.js with fullcalendar. http://blog.shinetech.com/2011/08/05/building-a-shared-calendar-with-backbone-js-and-fullcalendar-a-step-by-step-tutorial/ provides code and a tutorial explaining it. It's a bit of an extreme solution for what you're asking to accomplish but the benefits of using backbone.js with fullcalendar may be worth exploring.



来源:https://stackoverflow.com/questions/8858426/fullcalendar-json-feed-caching

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!