-
Notifications
You must be signed in to change notification settings - Fork 275
/
recache.rb
44 lines (41 loc) · 1.2 KB
/
recache.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true
class Shrine
module Plugins
# The `recache` plugin allows you to process your attachment after
# validations succeed, but before the attachment is promoted. This is
# useful for example when you want to generate some versions upfront (so
# the user immediately sees them) and other versions you want to generate
# in the promotion phase in a background job.
#
# plugin :recache
# plugin :processing
#
# process(:recache) do |io, context|
# # perform cheap processing
# end
#
# process(:store) do |io, context|
# # perform more expensive processing
# end
#
# Recaching will be automatically triggered in a "before save" callback,
# but if you're using the attacher directly, you can call it manually:
#
# attacher.recache if attacher.changed?
module Recache
module AttacherMethods
def save
recache
super
end
def recache
if cached?
recached = cache!(get, action: :recache)
_set(recached)
end
end
end
end
register_plugin(:recache, Recache)
end
end