View Source Nebulex.Adapter.Queryable behaviour (Nebulex v2.5.1)
Specifies the query API required from adapters.
query-values
Query values
There are two types of query values. The ones shared and implemented by all adapters and the ones that are adapter specific.
common-queries
Common queries
The following query values are shared and/or supported for all adapters:
nil
- Matches all cached entries.
adapter-specific-queries
Adapter-specific queries
The query
value depends entirely on the adapter implementation; it could
any term. Therefore, it is highly recommended to see adapters' documentation
for more information about building queries. For example, the built-in
Nebulex.Adapters.Local
adapter uses :ets.match_spec()
for queries,
as well as other pre-defined ones like :unexpired
and :expired
.
Link to this section Summary
Link to this section Types
@type adapter_meta() :: Nebulex.Adapter.adapter_meta()
Proxy type to the adapter meta
@type opts() :: Nebulex.Cache.opts()
Proxy type to the cache options
Link to this section Callbacks
@callback execute( adapter_meta(), operation :: :all | :count_all | :delete_all, query :: term(), opts() ) :: [term()] | integer()
Executes the query
according to the given operation
.
Raises Nebulex.QueryError
if query is invalid.
In the the adapter does not support the given operation
, an ArgumentError
exception should be raised.
operations
Operations
:all
- Returns a list with all entries from cache matching the givenquery
.:count_all
- Returns the number of matched entries with the givenquery
.:delete_all
- Deletes all entries matching the givenquery
. It returns the number of deleted entries.
It is used on Nebulex.Cache.all/2
, Nebulex.Cache.count_all/2
,
and Nebulex.Cache.delete_all/2
.
@callback stream(adapter_meta(), query :: term(), opts()) :: Enumerable.t()
Streams the given query
.
Raises Nebulex.QueryError
if query is invalid.