jsonapi-rb / jsonapi-rails

Rails gem for fast jsonapi-compliant APIs.
http://jsonapi-rb.org
MIT License
319 stars 63 forks source link

Add documentation for using a cache #66

Open julianhirt opened 6 years ago

julianhirt commented 6 years ago

Hi there, I do find the default values for jsonapi_cache and default initializers, but is it possible to add some documentation? I have a very static json and it would be awesome to have it cached somewhere. Thanks in advance!

beauby commented 6 years ago

Hi @julianhirt – it is planned but I'm rather busy at the moment so can't really give an ETA on the docs. In the meantime, feel free to ask any question you may have (either here or on gitter).

samnang commented 6 years ago

@beauby I couldn't find any doc on how to setup it with rails. I have few questions:

  1. How do I setup to integrate with Rails.cache?
  2. When I want to have cache functionality, do we pass some options in controller#render jsonapi: ... or I just define some option in my serializers?
  3. Do I have to always override cache key for each serializer or there is some default cache key?
  4. When I render a resource that includes relationships, are nested relationships required to override cache key, or we just only define in top/root resource only?
julianhirt commented 6 years ago

Any updates on this?

ssalzberg commented 6 years ago

Following up on this as well... I'm trying to implement caching by adding the "cache: Rails.cache" option to "render jsonapi: ...", but seeing this error:

NoMethodError (undefined method `as_jsonapi' for nil:NilClass Did you mean? as_json):

batdevis commented 5 years ago

same for me, adding

  config.jsonapi_cache = lambda {
    Rails.cache
  }

to the initializer

mbobin commented 5 years ago

The error is fixed with this commit https://github.com/jsonapi-rb/jsonapi-renderer/commit/f154799ff0d0ea8132b4e7acd632060cb0f7d22c, but it was not released. ☹️