Files
discord.js/docs/docs_cache.rst
Évelyne Lachance 1577075e52 Cache now returns null when using get(cacheID) with invalid ID (#441)
* Cache now returns `null` when using get(cacheID) where the ID is invalid.

* Documented `get(id)`

* Adjusted version in conf.py to 8.0.0
2016-06-26 13:30:24 +09:00

60 lines
1.5 KiB
ReStructuredText

.. include:: ./vars.rst
Cache
=====
**extends Array**
A Cache object extends an Array (so it can be used like a regular array) but introduces helper functions to make it more useful when developing with discord.js. Unlike a regular array, it doesn't care about the instance or prototype of an object, it works purely on properties.
**Examples:**
.. code-block:: js
client.users.get("id", 11238414);
client.channels.getAll("name", "general");
--------
Functions
---------
get(key, value)
~~~~~~~~~~~~~~~
Returns a contained object where ``object[key] == value``. Also works if value is a regex or a function. Returns the first object found that matches the criteria.
get(value)
Returns a contained object where ``object["id"] == value``. Shorthand for ``get("id", value)``. Returns ``null`` if ID is not found.
getAll(key, value)
~~~~~~~~~~~~~~~~~~
Similar to ``cache.get(key, value)``, but returns a Cache of any objects that meet the criteria.
has(key, value)
~~~~~~~~~~~~~~~
Returns `true` if there is an object that meets the condition ``object[key] == value`` in the cache
add(data)
~~~~~~~~~
Adds an object to the Cache as long as all the other objects in the cache don't have the same ID as it.
update(old, data)
~~~~~~~~~~~~~~~~~
Updates an old object in the Cache (if it exists) with the new one.
remove(data)
~~~~~~~~~~~~
Removes an object from the cache if it exists.
random()
~~~~~~~~~~~~
Get a random object from the cache.