lib/plezi/common/cache.rb in plezi-0.12.16 vs lib/plezi/common/cache.rb in plezi-0.12.17
- old
+ new
@@ -10,12 +10,10 @@
# contains the cached data, in the format: CACHE_STORE["filename"] = CacheObject
CACHE_STORE = {}
CACHE_LOCK = Mutex.new
CACHABLE = (%w{cache object slim haml css map js html scss sass coffee txt xml json yaml rb}).to_set
- @cache_to_disk = true
-
# this class holds cached objects (data and modification times)
class CacheObject
# Cached attributes
attr_accessor :data, :mtime
@@ -90,14 +88,33 @@
# returns true if the file exists on disk or in the cache.
def file_exists? filename
( CACHE_STORE[filename] || File.exist?(filename) ) && true
end
- # returns true if the file has been update since data was last cached.
+ # returns true if the {#allow_cache_update?} is true and the file has been update since data was last cached.
def cache_needs_update? filename
- return true if CACHE_STORE[filename].nil? || CACHE_STORE[filename].mtime < File.mtime(filename)
+ return true if CACHE_STORE[filename].nil? || (CACHE_STORE[filename].mtime < File.mtime(filename))
false
end
+
+ # # # The following was discarded because benchmarks show the difference is negligible
+ # @refresh_cache ||= (ENV['ENV'] != 'production')
+ # # get the cache refresh directive for {#cache_needs_update}. Defaults to ENV['ENV'] != 'production'
+ # def allow_cache_update?
+ # @refresh_cache ||= (ENV['ENV'] != 'production')
+ # end
+ # # set the cache refresh directive for {#cache_needs_update}
+ # def allow_cache_update= val
+ # @refresh_cache = val
+ # end
+ # # returns true if the {#allow_cache_update?} is true and the file has been update since data was last cached.
+ # def cache_needs_update? filename
+ # return true if CACHE_STORE[filename].nil? || (allow_cache_update? && (CACHE_STORE[filename].mtime < File.mtime(filename)))
+ # false
+ # end
+
+
+
end
public
extend Plezi::Cache