Skip to content

jinzhu/cacheAjax

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

= jQuery.cacheAjax 

== How to use?

=== $.cacheAjax
    $.cacheAjax() is a drop-in replacement for $.ajax().

    but what make it special ? the following:
      cache your ajax requests:
        oops,of course!
      force a new ajax request:
        $.cacheAjax({ force : true })
      customize cache key ( default use 'url + data' )
        $.cacheAjax({ key : customized_key })
      set timeout:
        set timeout for each request:
          $.cacheAjax({ timeout : 2000 }) // 2 seconds
        set global timeout:
          $.setCacheTimeout(2000)     // 2 seconds
          $.setCacheTimeout(false)    // never expire

=== $.expireCache
  $.expireCache(/regexp/)
    expire all key match /regexp/

  $.expireCache('string-key')
    expire 'string-key'

  $.expireCache()
    default expire `document.location.hash`,use the following to reset the default:
      $.setCacheDefaultKey('string');
        // use 'string' as default
      $.setCacheDefaultKey(function(){});
        // use the function's return value as default

=== A small sample:
  $.cacheAjax({
    url : '/pictures'
    dataType: 'script'
    success: function(e){
      console.log(e);
    },
    force : true,
    key : 'customized_key',
    timeout : 2000
  });

  $.expireCache(/album\/\d+\/picture(s)?/);

== How To Run Test ?
  $ sudo gem install sinatra
  $ ruby server.rb
  $ open '127.0.0.1:4567' in browser


Copyright (c) 2009  Dual licensed under the MIT and GPL
  Author : Jinzhu Zhang
  Github : http://github.com/jinzhu
  Email  : wosmvp (no-spam) gmail (no-spam) com

About

jquery plugin to cache ajax request and more.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published