к каталогу

📦 identity_cache/ Shopify

IdentityCache is a blob level caching solution to plug into Active Record. Don't #find, #fetch!

Открыть на GitHubобновлён 2мес назад
Звёзды
2.0k
Форки
173
За неделю
За месяц
Рост %
Язык
Ruby

Установка и запуск

Installation

Add this line to your application's Gemfile:

gem 'identity_cache'
gem 'cityhash'        # optional, for faster hashing (C-Ruby only)

gem 'dalli' # To use :mem_cache_store
# alternatively
gem 'memcached_store' # to use the old libmemcached based client

And then execute:

$ bundle

Add the following to all your environment/*.rb files (production/development/test):

Basic Usage

class Image < ActiveRecord::Base
  include IdentityCache::WithoutPrimaryIndex
end

class Product < ActiveRecord::Base
  include IdentityCache

  has_many :images

  cache_has_many :images, embed: true
end

# Fetch the product by its id using the primary index as well as the embedded images association.
@product = Product.fetch(id)

# Access the loaded images for the Product.
@images = @product.fetch_images

Note: You must include the IdentityCache module into the classes where you want to use it.

Из README репозитория · полный README на GitHub

Категории

Теги

activerecordcachewebscale