1 | module.exports = (providerParams) ->
|
2 | {$log} = providerParams
|
3 | ResourceCacheEntry = require('./resource_cache_entry')(providerParams)
|
4 |
|
5 | class ResourceCacheArrayEntry extends ResourceCacheEntry
|
6 | defaultValue: []
|
7 | cacheKeyPrefix: -> "#{@key}/array"
|
8 |
|
9 | addInstances: (instances, dirty, options = {append: false}) ->
|
10 | cacheArrayReferences = if options.append then @value else []
|
11 | cacheArrayReferences ?= []
|
12 |
|
13 | for instance in instances
|
14 | cacheInstanceParams = instance.$params()
|
15 | if Object.keys(cacheInstanceParams).length is 0
|
16 | $log.error """
|
17 | '#{@key}' instance doesn't have any boundParams. Please, make sure you specified them in your resource's initialization, f.e. `{id: "@id"}`, or it won't be cached.
|
18 | """
|
19 | else
|
20 | cacheArrayReferences.push cacheInstanceParams
|
21 | cacheInstanceEntry = new ResourceCacheEntry(@key, cacheInstanceParams).load()
|
22 |
|
23 | unless options.append and cacheInstanceEntry.value?
|
24 | cacheInstanceEntry.set instance, dirty
|
25 | @set cacheArrayReferences, dirty
|