Skip to content

Commit e33f0d0

Browse files
committedMar 16, 2015
Don’t depend on sprockets caching
Which has been removed in sprockets v3
1 parent 93f182c commit e33f0d0

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed
 

‎lib/opal/sprockets/source_map_server.rb

+37-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,47 @@
1-
require 'sprockets/caching'
2-
31
module Opal
42
class SourceMapServer
3+
# Carelessly taken from Sprockets::Caching (Sprockets v2)
54
class Cache
6-
include ::Sprockets::Caching
75
def initialize
86
@cache = {}
97
end
8+
109
attr_reader :cache
10+
11+
def cache_get(key)
12+
# `Cache#get(key)` for Memcache
13+
if cache.respond_to?(:get)
14+
cache.get(key)
15+
16+
# `Cache#[key]` so `Hash` can be used
17+
elsif cache.respond_to?(:[])
18+
cache[key]
19+
20+
# `Cache#read(key)` for `ActiveSupport::Cache` support
21+
elsif cache.respond_to?(:read)
22+
cache.read(key)
23+
24+
else
25+
nil
26+
end
27+
end
28+
29+
def cache_set(key, value)
30+
# `Cache#set(key, value)` for Memcache
31+
if cache.respond_to?(:set)
32+
cache.set(key, value)
33+
34+
# `Cache#[key]=value` so `Hash` can be used
35+
elsif cache.respond_to?(:[]=)
36+
cache[key] = value
37+
38+
# `Cache#write(key, value)` for `ActiveSupport::Cache` support
39+
elsif cache.respond_to?(:write)
40+
cache.write(key, value)
41+
end
42+
43+
value
44+
end
1145
end
1246

1347
def self.get_map_cache(sprockets, logical_path)

0 commit comments

Comments
 (0)
Please sign in to comment.