Skip to content

Add #cache_key method to models #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/flex_commerce_api/api_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ def template_attribute(key)
end
end

def cache_key
if respond_to?(:id) && respond_to?(:updated_at) && id && updated_at
[self.class.name, id, updated_at.to_datetime.utc.to_i.to_s].join("/")
else
raise NotImplementedError, "This model doesn't have an id/updated_at field, so requires custom #cache_key implementation"
end
end

def method_missing(method, *args)
if relationships and relationships.has_attribute?(method)
super
Expand Down