Class: Cache

PD.PathPoint. Cache

A utility class for caching path points.

The aim of this class is to minimise new memory allocations when regenerating paths by reusing a cache of previously created path points. It is typically used by elements that need to dynamically regenerate paths for dependant components.


new Cache()

Author:
  • drajmarsh
See:

Methods


_createNewPoint()

Creates a new path point instance for the cache.

Subclasses can override this method to create a different type of point that is suitable for their own paths.

Returns:

Returns a new path point instance.

Type
PD.PathPoint

clear()

Clears the cache and all its allocated memory.

Returns:

Returns this instance to support method chaining.

Type
PD.PathPoint.Cache

expandBy(count)

Expands the point cache by the given number of entries, if required.

Parameters:
Name Type Description
count number

The number of additional entries required.

Returns:

Returns this instance to support method chaining.

Type
PD.PathPoint.Cache

getCacheSize()

Retrieves the number of entries in the point cache.

Returns:

Returns the point cache size.

Type
number

getNextPoint()

Reuses an existing path point or creates a new one.

Returns:

Returns a reused or new point.

Type
PD.PathPoint

getNextPointIndex()

Retrieve the index of the next available point in the cache.

Returns:

Returns the current next point index.

Type
number

reuseEnd()

Finalises the shape.

This method must be called after you have first called reuseStart() to reset the reusable index. Its role is to trim any excessive leftover data that has not been reused.

Returns:

Returns this instance to support method chaining.

Type
PD.PathPoint.Cache

reuseStart()

Resets the point cache to begin reusing them.

Returns:

Returns this instance to support method chaining.

Type
PD.PathPoint.Cache

setCacheSize(new_size)

Sets the size of the point cache to the given number of entries.

You can use this method to either reduce or expand the size of the cache if you know the projected requirements beforehand.

Parameters:
Name Type Description
new_size number

The new size of the cache.

Returns:

Returns this instance to support method chaining.

Type
PD.PathPoint.Cache