Last active
February 28, 2016 12:41
-
-
Save amcdnl/f14cbfc3738668457ebb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(['angular'], function(angular){ | |
var module = angular.module('utils.cache', ['restmod') | |
// Cache implementation for angular-restmod | |
// https://github.com/platanus/angular-restmod/issues/27 | |
module.factory('CacheModel', function(restmod){ | |
var mixin = restmod.mixin(function() { | |
var cache = {}; | |
// Cache overrides | |
// ------------------------------------------------------------ | |
this.classDefine('$fetch', function() { | |
var url = this.$url(), | |
cached = cache[this.$url()]; | |
if(cached){ | |
return cached; | |
} else { | |
return cache[url] = this.$super.apply(this, arguments); | |
} | |
}); | |
this.classDefine('$find', function(_pk) { | |
var url = this.$urlFor(_pk), | |
cached = cache[url]; | |
if(cached){ | |
return cached; | |
} else { | |
return cache[url] = this.$super.apply(this, arguments); | |
} | |
}); | |
// set a pointer for cache | |
this.classDefine('$cache', cache); | |
}); | |
return mixin; | |
}); | |
return module; | |
}); |
@kenborge - Ya I thought about something like that. Managing the list(s) and singles together gets tricky.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To return results from
$search
when doing a$find
with an id$search
returned you could do something like