View Source Cachex.Query (Cachex v4.0.3)

Utility module based around creation of cache queries.

Queries are essentially just some minor convenience wrappers around the internal match specification used by ETS. This module is exposed to make it easier to query a cache (via Cachex.stream/3) without having to take care of filtering for expirations by hand.

Note that there is almost no validation in here, so test thoroughly and store compile-time versions of your queries when possible (as performance is not taken into account inside this module; it can be slow to generate).

Summary

Functions

Create a query specification for a cache.

Create a filter against expired records in a cache.

Create a filter against unexpired records in a cache.

Functions

@spec build(options :: Keyword.t()) :: [{tuple(), [tuple()], [any()]}]

Create a query specification for a cache.

This is a convenience binding to ETS select specifications, so please see the appropriate documentation for any additional information on how to (e.g.) format filter clauses and outputs.

Options

  • :output

    The query output format, which defaults to :entry (retrieving the entire cache entry). You can provide any of the entry record fields, with bindings such as tuples ({:key, :value}) or lists [:key, :value] or as a single value (:key).

  • :where

    An ETS filter condition used to locate records in the table. This defaults to retrieving all records, and is automatically joined with the value of the :expired flag for convenience.

@spec expired(filter :: boolean() | tuple() | nil) :: tuple()

Create a filter against expired records in a cache.

This function accepts a subfilter to join to create more complex filters.

Link to this function

unexpired(filter \\ nil)

View Source
@spec unexpired(filter :: boolean() | tuple() | nil) :: tuple()

Create a filter against unexpired records in a cache.

This function accepts a subfilter to join to create more complex filters.