# Class MaterialCache

A cache for storing and retrieving materials.

##### Index

### Constructors

constructor

### Methods

dispose
getOrAddMaterial

## Constructors

### constructor

- new MaterialCache(): MaterialCache

  Creates an instance of MaterialCache.

  #### Returns MaterialCache

## Methods

### dispose

- dispose(): void

  #### Returns void

### getOrAddMaterial

- getOrAddMaterial<T extends CullingMaterial, CTX = undefined>(
  key: string,
  scene: Scene,
  factory: (key: string, scene: Scene, context?: CTX) => T,
  context?: CTX,
  ): T

  Retrieves a material from the cache if it exists, otherwise creates a new material using the provided factory function, adds it to the cache, and returns it.

  #### Type Parameters

  - T extends CullingMaterial

    The type of the material, extending CullingMaterial.

  - CTX = undefined

  #### Parameters

  - key: string

    The key associated with the material.

  - scene: Scene

    The scene to which the material belongs.

  - factory: (key: string, scene: Scene, context?: CTX) => T

    A factory function to create a new material if it does not exist in the cache.

  - `Optional` context: CTX

  #### Returns T

  The material associated with the given key.