DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
    • can-component
    • can-compute
    • can-connect
      • behaviors
        • ./base/
        • ./cache-requests/
        • ./can/map/
        • ./can/ref/
        • ./constructor/callbacks-once/
        • ./constructor/
        • ./constructor/store/
        • ./data/callbacks/
        • ./data/callbacks-cache/
        • ./data/combine-requests/
        • ./data/localstorage-cache/
        • ./data/memory-cache/
        • ./data/parse/
        • ./data/url/
        • ./data/worker/
        • ./fall-through-cache/
          • hydrators
            • hydrateInstance
            • hydrateList
          • data callbacks
            • getData
            • getListData
        • ./real-time/
      • modules
        • ./can/base-map/
        • ./can/model/
        • ./can/super-map/
        • ./can/tag/
        • ./helpers/weak-reference-map
      • data types
        • DataInterface
        • Instance
        • InstanceInterface
        • List
        • ListData
    • can-define
    • can-define/list/list
    • can-define/map/map
    • can-route
    • can-route-pushstate
    • can-set
    • can-stache
    • can-stache/helpers/route
    • can-stache-bindings
  • Ecosystem
  • Infrastructure
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Core
  • /
  • can-connect
  • /
  • ./fall-through-cache/
  • / On this page
    • can-connect/fall-through-cache/fall-through-cache

      module

      A fall through cache that checks another cacheConnection.

      • source

      fallThroughCache( baseConnection )

      Implements a getData and getListData that check their cacheConnection for data and then in the background update the instance or list with data retrieved using the base connection.

      Use

      To use the fall-through-cache, create a connection with a cacheConnection and a behavior that implements getData and getListData.

      var cache = connect([
        require("can-connect/data/localstorage-cache/localstorage-cache")
      ],{
        name: "todos"
      });
      
      var todoConnection = connect([
         require("can-connect/fall-through-cache/fall-through-cache"),
         require("can-connect/data/url/url"),
         require("can-connect/constructor/constructor"),
         require("can-connect/constructor/store/store")
        ], {
        url: "/todos",
        cacheConnection: cache
      });
      

      Then, make requests. If the cache has the data, it will be returned immediately, and then the item or list updated later with the response from the base connection:

      todoConnection.getList({due: "today"}).then(function(todos){
      
      })
      

      Demo

      The following shows the fall-through-cache behavior.

      Clicking "Completed" or "Incomplete" will make one of the following requests and display the results in the page:

      todoConnection.getList({completed: true});
      todoConnection.getList({completed: false});
      

      If you click back and forth between "Completed" and "Incomplete" multiple times you'll notice that the old data is displayed immediately and then updated after about a second.

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.