{"action":"created","issue":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/893","labels_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/893/labels{/name}","comments_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/893/comments","events_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/893/events","html_url":"https://github.com/rails-api/active_model_serializers/issues/893","id":72027601,"number":893,"title":"Dynamic cache keys","user":{"login":"apolzon","id":223493,"avatar_url":"https://avatars.githubusercontent.com/u/223493?v=3","gravatar_id":"","url":"https://api.github.com/users/apolzon","html_url":"https://github.com/apolzon","followers_url":"https://api.github.com/users/apolzon/followers","following_url":"https://api.github.com/users/apolzon/following{/other_user}","gists_url":"https://api.github.com/users/apolzon/gists{/gist_id}","starred_url":"https://api.github.com/users/apolzon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apolzon/subscriptions","organizations_url":"https://api.github.com/users/apolzon/orgs","repos_url":"https://api.github.com/users/apolzon/repos","events_url":"https://api.github.com/users/apolzon/events{/privacy}","received_events_url":"https://api.github.com/users/apolzon/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-30T00:47:53Z","updated_at":"2015-04-30T00:54:56Z","closed_at":null,"body":"AMS 0.10 is really looking great, thanks for all the work thats gone into it.\r\n\r\nThe one thing I'm looking for that I don't believe is currently possible is a way to cache serializers on a per-user (or some other runtime-attribute) basis.\r\n\r\nie, I'd like to specify my cache key as:\r\n\r\n```ruby\r\ncache key: \"project\", additional_models: [current_user]\r\n```\r\n(current_user being the serialization scope)\r\n\r\nor, if the cache key attribute supported a lambda:\r\n```ruby\r\ncache key: -> { \"project/#{current_user.id}-#{current_user.updated_at}\" }\r\n```\r\n\r\nI guess another approach would be to pass the serialization scope to object.cache_key.\r\n\r\nThanks."},"comment":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/comments/97623051","html_url":"https://github.com/rails-api/active_model_serializers/issues/893#issuecomment-97623051","issue_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/893","id":97623051,"user":{"login":"joaomdmoura","id":667063,"avatar_url":"https://avatars.githubusercontent.com/u/667063?v=3","gravatar_id":"","url":"https://api.github.com/users/joaomdmoura","html_url":"https://github.com/joaomdmoura","followers_url":"https://api.github.com/users/joaomdmoura/followers","following_url":"https://api.github.com/users/joaomdmoura/following{/other_user}","gists_url":"https://api.github.com/users/joaomdmoura/gists{/gist_id}","starred_url":"https://api.github.com/users/joaomdmoura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joaomdmoura/subscriptions","organizations_url":"https://api.github.com/users/joaomdmoura/orgs","repos_url":"https://api.github.com/users/joaomdmoura/repos","events_url":"https://api.github.com/users/joaomdmoura/events{/privacy}","received_events_url":"https://api.github.com/users/joaomdmoura/received_events","type":"User","site_admin":false},"created_at":"2015-04-30T00:54:56Z","updated_at":"2015-04-30T00:54:56Z","body":"Hey @apolzon, I'm glad you are enjoying AMS 0.10\r\n\r\nIndeed, the only way of doing this today would be interpolating string as key:\r\n\r\n```ruby\r\ncache key: \"project-#{current_user.id}-#{current_user.updated_at}\"\r\n```\r\n\r\nI'm not sure what is your use case, but having cache per user may not scale as you might need.\r\nBut you could use [fragment cache](https://github.com/rails-api/active_model_serializers#fragmenting-caching), so you can cache only the attributes that makes sense to be cache to ever user."}}