From 3fa6ca4e1eb5c600a81232b394dd9e374c054054 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 12 May 2020 12:50:22 -0300 Subject: [PATCH] =?UTF-8?q?invalidar=20la=20cach=C3=A9=20si=20el=20post=20?= =?UTF-8?q?cambia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/post.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/models/post.rb b/app/models/post.rb index 36b36e2..e3ada41 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -75,10 +75,21 @@ class Post < OpenStruct 'posts/' + uuid.value end + def cache_version + updated_at.utc.to_s(:usec) + end + + # Agregar el timestamp para saber si cambió, siguiendo el módulo + # ActiveRecord::Integration + def cache_key_with_version + cache_key + '-' + cache_version + end + # TODO: Convertir a UUID? def id path.basename end + alias to_param id def updated_at File.mtime(path.absolute)