https://github.com/hissssst/nebulex_adapters_ecto
Postgres Ecto Adapter for Nebulex Cache
https://github.com/hissssst/nebulex_adapters_ecto
Last synced: 3 months ago
JSON representation
Postgres Ecto Adapter for Nebulex Cache
- Host: GitHub
- URL: https://github.com/hissssst/nebulex_adapters_ecto
- Owner: hissssst
- License: bsd-2-clause
- Created: 2023-08-16T15:01:39.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-08T16:25:15.000Z (about 1 year ago)
- Last Synced: 2025-04-02T18:54:50.505Z (6 months ago)
- Language: Elixir
- Size: 29.3 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Nebulex.Adapters.Ecto
Extremely simple Ecto Postgres adapter for Nebulex Cache library.
Designed to be used as the last level adapter inside multilevel cache.This adapter implements:
1. Basic key-value cache interface.
2. Cache transactions.
3. Basic queries without patterns.Cache eviction strategy is LRW or LRU based on the last touched timestamp.
## Installation
In `mix.exs`:
```elixir
defp deps do
[
{:nebulex_adapters_ecto, "~> 1.0"}
]
end
```## Setup
### Configuration
In your `runtime.exs`:
```elixir
config :my_app, MyApp.Cache,
# Available strategies are LRW and LRU
strategy: :lrw,# Repository to be used to access table with cache
repo: MyApp.Repo,# The table as a string (or Schema) which will hold cache data
table: "cache_table",# Maximum amount of data present in the table (in rows)
max_amount: 1000,# Timeout of garbage collection in milliseconds
gc_timeout: :timer.hours(2),# The function to generate timestamps in milliseconds
timestamp_mfa: {:erlang, :system_time, [:millisecond]}
```### Table
The most simple migration for cache table would look like this:
```elixir
defmodule Nebulex.Adapters.EctoTest.Repo.Migrations.CreateCacheTable do
use Ecto.Migrationdef change do
create table "cache_table" do
add :key, :binary, primary_key: true
add :value, :binary
add :touched_at, :bigint
add :ttl, :integer
endcreate unique_index("cache_table", :key)
end
end
```However, feel free to create your own indexes. For example, to speed up
garbage collection, I'd suggest using `touched_at + ttl` btree index.