Kendo ToolTip: How to cache your ajax response?

Today I had a task to make ToolTip that cache the response from ajax request. But the problem is that KendoUI ToolTip doesn’t supports option for enabling the cache. By default they set “false” value to “cache” property in $.ajax method. Also by default you can’t chose the type of request (POST/GET). Now I’ll show you how I resolved the problem.

You should to put this code after initializing your tooltip:

kendo.ui.Tooltip.fn._ajaxRequest = function (options) {
var that = this;
type: "POST",
dataType: "html",
cache: true,
error: function (xhr, status) {
kendo.ui.progress(that.content, false);
that.trigger(ERROR, {
status: status,
xhr: xhr
success: $.proxy(function (data) {
kendo.ui.progress(that.content, false);
}, that)
}, options));

The highlighted rows are my changes. I changed the “type” to “POST” and I enabled caching. Now I’ll make my action to cache the response in controller.

[OutputCache(Duration=3600, Location=OutputCacheLocation.ServerAndClient, VaryByParam="myDynamicId")]
public ActionResult GetCarInfromation(int myDynamicId)
            var myQueryResult = db.Cars.Single(x => x.CarId == myDynamicId);
            return View("_myPartialView", myQueryResult);

I setted the duration to be 3600 seconds and cache location to be to the server side and to the client side. Also I setted my dynamic parameter(“myDynamicId”) with “VaryByParam” attribute.

Now the response from action are cached for 1 hour. This should to improve your performance and usually makes time for response two times faster.

You can read more about caching and performance in mvc here


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s