【发布时间】:2022-02-03 20:38:33
【问题描述】:
目前使用 jsonapi-rails 渲染序列化对象,同时利用一些隔离缓存。
JSON.generate JSONAPI::Rails::SuccessRenderer.new.render(
all_data,
{
include: %w(attr_1 attr_2),
meta: {
total: all_data.size
},
expose: {
url_helpers: ::Rails.application.routes.url_helpers,
language: language,
},
cache: SerializedObjectsCache.instance
},
controller
)
# SerializedObjectsCache
def self.instance
@instance ||=
begin
cache = ActiveSupport::Cache::RedisCacheStore.new(
redis: Redis.current,
compress: COMPRESS,
namespace: 'serialized_objects',
expires_in: EXPIRES_IN
)
new(cache)
end
end
我想弄清楚我们丢失/命中缓存的频率。每个序列化对象都有一个 jsonapi_cache_key 方法来为每个对象返回一个唯一键,但我不确定如何查看缓存命中/未命中率。
【问题讨论】:
标签: ruby-on-rails ruby json-api jsonapi-rails