-
Notifications
You must be signed in to change notification settings - Fork 63
/
ldp_cache.rb
46 lines (37 loc) · 1.06 KB
/
ldp_cache.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
45
module ActiveFedora
# = Active Fedora Ldp Cache
class LdpCache
module ClassMethods
# Enable the query cache within the block if Active Fedora is configured.
# If it's not, it will execute the given block.
def cache(&block)
connection = ActiveFedora.fedora.connection
connection.cache(&block)
end
# Disable the query cache within the block if Active Fedora is configured.
# If it's not, it will execute the given block.
def uncached(&block)
ActiveFedora.fedora.connection.uncached(&block)
end
end
def initialize(app)
@app = app
end
def call(env)
ActiveFedora.fedora.connection.enable_cache!
response = @app.call(env)
response[2] = Rack::BodyProxy.new(response[2]) do
reset_cache_settings
end
response
rescue Exception => e
reset_cache_settings
raise e
end
private
def reset_cache_settings
ActiveFedora.fedora.connection.clear_cache
ActiveFedora.fedora.connection.disable_cache!
end
end
end