ExAirtable.TableCache (ExAirtable v0.2.9) View Source

A caching server for an ExAirtable.Table.

Given a module name that implements the Table behaviour, it will automatically spawn synchronization processes and provide an in-memory data store that stays in sync with the external Airtable table/base.

Examples

iex> TableCache.retrieve(MyAirtableTable, "rec1234")
%Airtable.Record{}

iex> TableCache.list(MyAirtableTable)
%Airtable.List{records: [%Airtable.Record{}, ...]}

Link to this section Summary

Types

t()

A struct that contains the state for a TableCache.

Functions

Returns a specification to start this module under a supervisor.

Given an ExAirtable.Table module and an ID map, delete the record matching that ID.

Initialize the caching server.

Given an ExAirtable.Table module, get all %Airtable.Record{}s in that cache's table as an %Airtable.List{}.

Given an ExAirtable.Table module, and a list result, store that result for later cache replacement.

Given an ExAirtable.Table module and a string key, get the %Record{} in that cache with the matching key.

Given an ExAirtable.Table module, an ID, and a corresponding item to match that ID, store it in the cache.

Replace an entire cache with a new set of %ExAirtable.Airtable.Record{}s.

Start a caching server.

Returns a valid ETS table name for a given ExAirtable.Table module.

Given an ExAirtable.Table module and an ExAirtable.Airtable.Record{} struct, update the matching record in the cache, and insert it if it doesn't exist.

Link to this section Types

Specs

t() :: %ExAirtable.TableCache{
  hash: String.t(),
  sync_rate: integer(),
  sync_ref: pid(),
  table_module: module()
}

A struct that contains the state for a TableCache.

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

delete(table_module, map)

View Source

Given an ExAirtable.Table module and an ID map, delete the record matching that ID.

This is an asynchronous operation.

Initialize the caching server.

This is not meant to be called manually, but will be handle when start_link/1 is called.

See start_link/1 for options.

Given an ExAirtable.Table module, get all %Airtable.Record{}s in that cache's table as an %Airtable.List{}.

Link to this function

push_paginated_list(table_module, list)

View Source

Given an ExAirtable.Table module, and a list result, store that result for later cache replacement.

Once we have the final page in a paginated list (or a list that has less than 100 records), we can replace the cache.

This function is typically called by an async process to accumulate paginated data from Airtable's list method.

Link to this function

retrieve(table_module, key)

View Source

Given an ExAirtable.Table module and a string key, get the %Record{} in that cache with the matching key.

Link to this function

set(table_module, id, item)

View Source

Given an ExAirtable.Table module, an ID, and a corresponding item to match that ID, store it in the cache.

Link to this function

set_all(table_module, list)

View Source

Replace an entire cache with a new set of %ExAirtable.Airtable.Record{}s.

Start a caching server.

Valid options (in the opts field) include:

  • table_module (required) - The module name of the ExAirtable.Table module you're caching. If this is not included, the link will raise an error.
  • sync_rate - How often (in ms) to refresh data from Airtable.
  • skip_sync (boolean) - If you don't want to run the sync server for whatever reason (typically testing)

Returns a valid ETS table name for a given ExAirtable.Table module.

Link to this function

update(table_module, list)

View Source

Given an ExAirtable.Table module and an ExAirtable.Airtable.Record{} struct, update the matching record in the cache, and insert it if it doesn't exist.