github.com/crystal-cache/postgres_cache_store

Cache::Store implementation backed by a database via crystal-pg.

8 stars
0 dependents
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  postgres_cache_store:
    github: crystal-cache/postgres_cache_store
    version: ~> 1.0.0

Then run:

shards install

shard.yml

Crystal
>= 1.0.0
License
MIT
Author
Anton Maminov <anton.maminov@gmail.com>

Dependencies

Runtime Dependencies

  • pg>= 0.23.0github: will/crystal-pg
  • cache>= 1.0.0github: crystal-cache/cache

Development Dependencies

  • ameba*github: crystal-ameba/amebadev

README

# Cache::PostgresCacheStore

![Crystal CI](https://github.com/crystal-cache/postgres_cache_store/workflows/Crystal%20CI/badge.svg)
[![GitHub release](https://img.shields.io/github/release/crystal-cache/postgres_cache_store.svg)](https://github.com/crystal-cache/postgres_cache_store/releases)

A [cache](https://github.com/crystal-cache/cache) store implementation which stores everything in the Postgres database,
using [crystal-pg](https://github.com/will/crystal-pg) as the backend.

`Cache::PostgresCacheStore` is a Crystal cache backed by a Postgres UNLOGGED table and text column.

## Installation

1. Add the dependency to your `shard.yml`:

   ```yaml
   dependencies:
     postgres_cache_store:
       github: crystal-cache/postgres_cache_store
   ```

2. Run `shards install`

## Usage

Before using this shard make sure you have created Postgres database. For example `cache_production`:

```console
psql -c 'CREATE DATABASE cache_production;' -U postgres
```

A Postgres database can be opened with:

```crystal
db = DB.open("postgres://postgres@localhost/cache_production")
```

Open and use the new cache instance:

```crystal
require "postgres_cache_store"

cache = Cache::PostgresCacheStore(String).new(1.minute, db)

cache.write("foo", "bar")

cache.read("foo") # => "bar"
```

## Contributing

1. Fork it (<https://github.com/crystal-cache/postgres_cache_store/fork>)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request

## Contributors

- [Anton Maminov](https://github.com/mamantoha) - creator and maintainer