spark.core

# ContentCache - AS3 Flex

Package | spark.core
Class | public class ContentCache
Inheritance | ContentCache EventDispatcher Object
Implements | IContentLoader

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 1.5

Provides a caching and queuing image content loader suitable for using a shared image cache for the BitmapImage and spark Image components.

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object
|  | enableCaching : Boolean Enables caching behavior and functionality. | ContentCache
|  | enableQueueing : Boolean Enables queuing behavior and functionality. | ContentCache
|  | maxActiveRequests : int Maximum simultaneous active requests when queuing is enabled. | ContentCache
|  | maxCacheEntries : int Maximum size of MRU based cache. | ContentCache
|  | numCacheEntries : int [read-only] Count of active/in-use cache entries. | ContentCache

Protected Properties

| Property | Defined By
--- | --- | ---
|  | activeRequests : LinkedList List of queued CacheEntryNode instances currently executing. | ContentCache
|  | cachedData : Dictionary Map of source to CacheEntryNode. | ContentCache
|  | cacheEntries : LinkedList Ordered (MRU) list of CacheEntryNode instances. | ContentCache
|  | priorityGroup : String = "_DEFAULT_" Identifier of the currently prioritized content grouping. | ContentCache
|  | requestQueue : LinkedList List of queued CacheEntryNode instances. | ContentCache

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | ContentCache() Constructor. | ContentCache
|  | addCacheEntry(source:Object, value:Object):void Adds new entry to cache (or replaces existing entry). | ContentCache
|  | addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event. | EventDispatcher
|  | dispatchEvent(event:Event):Boolean Dispatches an event into the event flow. | EventDispatcher
|  | getCacheEntry(source:Object):Object Obtain an entry for the given key if one exists. | ContentCache
|  | hasEventListener(type:String):Boolean Checks whether the EventDispatcher object has any listeners registered for a specific type of event. | EventDispatcher
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | load(source:Object, contentLoaderGrouping:String = null):ContentRequest Initiates a content request for the resource identified by the key specified. | ContentCache
|  | prioritize(contentLoaderGrouping:String):void Promotes a content grouping to the head of the loading queue. | ContentCache
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | removeAllCacheEntries():void Resets our cache content to initial empty state. | ContentCache
|  | removeAllQueueEntries():void Resets the queue to initial empty state. | ContentCache
|  | removeCacheEntry(source:Object):void Remove specific entry from cache. | ContentCache
|  | removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void Removes a listener from the EventDispatcher object. | EventDispatcher
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Returns the string representation of the specified object. | Object
|  | valueOf():Object Returns the primitive value of the specified object. | Object
|  | willTrigger(type:String):Boolean Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type. | EventDispatcher

Events
Click for more information on events
Hide Inherited Events
Show Inherited Events

| Event | Summary | Defined By
--- | --- | --- | ---
|  | activate | [broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active. | EventDispatcher
|  | deactivate | [broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive. | EventDispatcher
|  | invalidateLoader | Dispatched when a cache entry is invalidated, generally this occurs when the entry is determined to be untrusted while one or more outstanding load requests are active for a given cache entry. | ContentCache

Protected Constants

| Constant | Defined By
--- | --- | ---
|  | UNTRUSTED : String = "untrusted" [static] Value used to mark cached URLs that are detected as being from an untrusted source (meaning they will no longer be shareable). | ContentCache

Property Detail

### activeRequests

property

`protected var activeRequests:LinkedList`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 1.5

List of queued CacheEntryNode instances currently executing.

### cachedData

property

`protected var cachedData:Dictionary`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 1.5

Map of source to CacheEntryNode.

### cacheEntries

property

`protected var cacheEntries:LinkedList`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 1.5

Ordered (MRU) list of CacheEntryNode instances.

### enableCaching

property

`enableCaching:Boolean`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 1.5

Enables caching behavior and functionality. Applies only to new load() requests.

The default value is `true.`

Implementation
`public function get enableCaching():Boolean`
`public function set enableCaching(value:Boolean):void`

### enableQueueing

property

`enableQueueing:Boolean`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 1.5

Enables queuing behavior and functionality. Applies only to new load() requests.

The default value is `false.`

Implementation
`public function get enableQueueing():Boolean`
`public function set enableQueueing(value:Boolean):void`

### maxActiveRequests

property

`maxActiveRequests:int`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 1.5

Maximum simultaneous active requests when queuing is enabled.

The default value is `2.`

Implementation
`public function get maxActiveRequests():int`
`public function set maxActiveRequests(value:int):void`

### maxCacheEntries

property

`maxCacheEntries:int`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 1.5

Maximum size of MRU based cache. When numCacheEntries exceeds maxCacheEntries the least recently used are pruned to fit.

The default value is `100.`

Implementation
`public function get maxCacheEntries():int`
`public function set maxCacheEntries(value:int):void`

### numCacheEntries

property

`numCacheEntries:int` [read-only]

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 1.5

Count of active/in-use cache entries.

Implementation
`public function get numCacheEntries():int`

### priorityGroup

property

`protected var priorityGroup:String = "_DEFAULT_"`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 1.5

Identifier of the currently prioritized content grouping.

The default value is `"_DEFAULT_".`

### requestQueue

property

`protected var requestQueue:LinkedList`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 1.5

List of queued CacheEntryNode instances.

Constructor Detail

### ContentCache

()
Constructor

`public function ContentCache()`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 1.5

Constructor.

Method Detail

### addCacheEntry

()
method

`public function addCacheEntry(source:Object, value:Object):void`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 1.5

Adds new entry to cache (or replaces existing entry).

Parameters

| `source:Object` — Unique key to associate provided value with in cache.
| `value:Object` — Value to cache for given key.

### getCacheEntry

()
method

`public function getCacheEntry(source:Object):Object`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 1.5

Obtain an entry for the given key if one exists.

Parameters

| `source:Object` — Unique key used to represent the requested content resource.

Returns

| `Object` — A value being stored by the cache for the provided key. Returns null if not found or in the likely case the value was stored as null.

### load

()
method

`public function load(source:Object, contentLoaderGrouping:String = null):ContentRequest`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 2.5

Initiates a content request for the resource identified by the key specified.

Parameters

| `source:Object` — Unique key used to represent the requested content resource. This parameter is typically an URL or URLRequest.
| `contentLoaderGrouping:String` (default = `null`)`` — - (Optional) grouping identifier for the loaded resource. ContentLoader instances supporting content groups generally allow for resources within the same named grouping to be addressed as a whole. For example the ContentCache's loader queue allows requests to be prioritized by contentLoaderGrouping.

Returns

| `ContentRequest` — A ContentRequest instance representing the requested resource.

### prioritize

()
method

`public function prioritize(contentLoaderGrouping:String):void`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 1.5

Promotes a content grouping to the head of the loading queue.

Parameters

| `contentLoaderGrouping:String` — Name of content grouping to promote in the loading queue. All queued requests with matching contentLoaderGroup will be shifted to the head of the queue.

### removeAllCacheEntries

()
method

`public function removeAllCacheEntries():void`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 1.5

Resets our cache content to initial empty state.

### removeAllQueueEntries

()
method

`public function removeAllQueueEntries():void`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 1.5

Resets the queue to initial empty state. All requests, both active and queued, are cancelled. All cache entries associated with canceled requests are invalidated.

### removeCacheEntry

()
method

`public function removeCacheEntry(source:Object):void`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 1.5

Remove specific entry from cache.

Parameters

| `source:Object` — Unique key for value to remove from cache.

Event Detail

### invalidateLoader

Event

Event Object Type: `spark.events.LoaderInvalidationEvent`
property LoaderInvalidationEvent.type = `spark.events.LoaderInvalidationEvent`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10, AIR 2.0

Dispatched when a cache entry is invalidated, generally this occurs when the entry is determined to be untrusted while one or more outstanding load requests are active for a given cache entry. This mechanism allows any outstanding content requests to be reset due to the fact that the cache entry has been deemed 'unshareable'. Each content request notified then attempts instead re-requests the asset.

Constant Detail

### UNTRUSTED

Constant

`protected static const UNTRUSTED:String = "untrusted"`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 9, AIR 1.1

Value used to mark cached URLs that are detected as being from an untrusted source (meaning they will no longer be shareable).

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00