Skip to content

Instantly share code, notes, and snippets.

@KamilLelonek
Last active August 29, 2015 14:08
Show Gist options
  • Save KamilLelonek/d9b3898093bd2a5d8109 to your computer and use it in GitHub Desktop.
Save KamilLelonek/d9b3898093bd2a5d8109 to your computer and use it in GitHub Desktop.
Fake cacheFactory for AngularJS
Extensions = angular.module 'MyApplication.ExtensionsModule', []
# ...
Extensions.factory '$templateCache', [
'$cacheFactory', '$http', '$injector', 'SecurityConstants',
($cacheFactory, $http, $injector, SecurityConstants) ->
cache = $cacheFactory('templates')
promise = undefined
info: cache.info
get: (url) ->
fromCache = cache.get(url)
return fromCache if fromCache
unless promise
promise = $http.get("#{SecurityConstants.assetsHost}/templates/partials.html")
.then((response) ->
$injector.get('$compile') response.data
response
)
promise.then (response) ->
status: response.status
data: cache.get(url)
put: (key, value) ->
cache.put key, value
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment