andrewisen-tikab / three-fifo-cache

FIFO cache implementation in three.js

Home Page:https://andrewisen-tikab.github.io/three-fifo-cache/example/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

three-fifo-cache

A First in first out (FIFO) cache implementation in three.js.

Installation

npm install three-fifo-cache

or

yarn add three-fifo-cache

Is this useful?

This class is useful in very specific situations. For most everyday usage, a simple traversal of the scene graph is enough.

let object = null;
scene.traverse((child) => {
    if (child.uuid === 'my-uuid') {
        object = child;
    }
});

However, if you have a large scene graph with multiple generations (children, grand-children, grand-grand-children, etc.) and you need to access a specific object multiple times, then this class can be useful.

Usage

First, import the module and setup the cache.

import FIFO from 'three-fifo-cache';

const maxItems = 10;
const cache = new FIFO(maxItems);

Then simply use the cache to store and retrieve items.

import * as THREE from 'three';

// Store an item
const object = new THREE.Object3D();
cache.set(object.uuid, object);

// Retrieve an item
const item = cache.get(object.uuid);

N.B: You can use any key you want.

Use flush to clear the cache.

cache.flush();

Example

A simple example is available in the example folder. Or, a live version is available at:

https://andrewisen-tikab.github.io/three-fifo-cache/example/

Docs

Auto-generated docs can be found here:

https://andrewisen-tikab.github.io/three-fifo-cache/docs/

Status

This is a work in progress. It has not been tested in production code.

About

FIFO cache implementation in three.js

https://andrewisen-tikab.github.io/three-fifo-cache/example/

License:MIT License


Languages

Language:TypeScript 97.0%Language:HTML 2.8%Language:CSS 0.2%