Class: SeoCache::PageCaching
- Inherits:
-
Object
- Object
- SeoCache::PageCaching
- Defined in:
- lib/seo_cache/page_caching.rb
Instance Method Summary collapse
- #cache(content, path, locale_domain = nil, extension = nil, gzip = Zlib::BEST_COMPRESSION) ⇒ Object
- #cache_exists?(path, locale_domain = nil, extension = nil) ⇒ Boolean
- #expire(path, locale_domain = nil, extension = nil) ⇒ Object
- #get(path, locale_domain = nil, extension = nil) ⇒ Object
-
#initialize ⇒ PageCaching
constructor
A new instance of PageCaching.
- #initialize_memory_cache ⇒ Object
Constructor Details
#initialize ⇒ PageCaching
Returns a new instance of PageCaching.
5 6 7 8 9 |
# File 'lib/seo_cache/page_caching.rb', line 5 def initialize @redis = nil initialize_memory_cache if SeoCache.memory_cache? end |
Instance Method Details
#cache(content, path, locale_domain = nil, extension = nil, gzip = Zlib::BEST_COMPRESSION) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/seo_cache/page_caching.rb', line 20 def cache(content, path, locale_domain = nil, extension = nil, gzip = Zlib::BEST_COMPRESSION) instrument :write_page, path do if SeoCache.memory_cache? && @redis write_to_memory(content, cache_path(path, locale_domain, extension)) else write_to_disk(content, cache_path(path, locale_domain, extension), gzip) end end end |
#cache_exists?(path, locale_domain = nil, extension = nil) ⇒ Boolean
36 37 38 39 40 41 42 |
# File 'lib/seo_cache/page_caching.rb', line 36 def cache_exists?(path, locale_domain = nil, extension = nil) if SeoCache.memory_cache? && @redis @redis.exists?(cache_path(path, locale_domain, extension)) else File.exist?(cache_path(path, locale_domain, extension)) end end |
#expire(path, locale_domain = nil, extension = nil) ⇒ Object
30 31 32 33 34 |
# File 'lib/seo_cache/page_caching.rb', line 30 def expire(path, locale_domain = nil, extension = nil) instrument :expire_page, path do delete(cache_path(path, locale_domain, extension)) end end |
#get(path, locale_domain = nil, extension = nil) ⇒ Object
16 17 18 |
# File 'lib/seo_cache/page_caching.rb', line 16 def get(path, locale_domain = nil, extension = nil) @redis.get(cache_path(path, locale_domain, extension)) if SeoCache.memory_cache? && @redis end |
#initialize_memory_cache ⇒ Object
11 12 13 14 |
# File 'lib/seo_cache/page_caching.rb', line 11 def initialize_memory_cache uri = URI.parse(SeoCache.redis_url) @redis = Redis::Namespace.new(SeoCache.redis_namespace, redis: Redis.new(host: uri.host, port: uri.port, password: uri.password, db: SeoCache.redis_db_index, connect_timeout: 1, timeout: 1), warnings: false) end |