Class: Opal::SourceMapServer::Cache
- Inherits:
- 
      Object
      
        - Object
- Opal::SourceMapServer::Cache
 
- Defined in:
- opal/lib/opal/sprockets/source_map_server.rb
Overview
Carelessly taken from Sprockets::Caching (Sprockets v2)
Instance Attribute Summary collapse
- 
  
    
      #cache  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute cache. 
Instance Method Summary collapse
- #cache_get(key) ⇒ Object
- #cache_set(key, value) ⇒ Object
- 
  
    
      #initialize  ⇒ Cache 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Cache. 
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache
| 5 6 7 | # File 'opal/lib/opal/sprockets/source_map_server.rb', line 5 def initialize @cache = {} end | 
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache
| 9 10 11 | # File 'opal/lib/opal/sprockets/source_map_server.rb', line 9 def cache @cache end | 
Instance Method Details
#cache_get(key) ⇒ Object
| 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # File 'opal/lib/opal/sprockets/source_map_server.rb', line 11 def cache_get(key) # `Cache#get(key)` for Memcache if cache.respond_to?(:get) cache.get(key) # `Cache#[key]` so `Hash` can be used elsif cache.respond_to?(:[]) cache[key] # `Cache#read(key)` for `ActiveSupport::Cache` support elsif cache.respond_to?(:read) cache.read(key) else nil end end | 
#cache_set(key, value) ⇒ Object
| 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | # File 'opal/lib/opal/sprockets/source_map_server.rb', line 29 def cache_set(key, value) # `Cache#set(key, value)` for Memcache if cache.respond_to?(:set) cache.set(key, value) # `Cache#[key]=value` so `Hash` can be used elsif cache.respond_to?(:[]=) cache[key] = value # `Cache#write(key, value)` for `ActiveSupport::Cache` support elsif cache.respond_to?(:write) cache.write(key, value) end value end |