def initialize(args = nil)
args ||= {}
@path = args[:path]
@expires_in_seconds = args[:expires_in] || EXPIRES_IN_SECONDS
raise ArgumentError.new :path unless @path
FileUtils.mkdir_p(@path) unless ::File.exists?(@path)
@timer_struct_cache = FileCache.new(@path, "mp_timers")
@timer_struct_lock = Mutex.new
@user_view_cache = FileCache.new(@path, "mp_views")
@user_view_lock = Mutex.new
me = self
t = CacheCleanupThread.new do
interval = 10
cleanup_cache_cycle = 3600
cycle_count = 1
begin
until Thread.current[:should_exit] do
if cycle_count * interval >= cleanup_cache_cycle
cycle_count = 1
me.cleanup_cache
end
sleep(interval)
cycle_count += 1
end
rescue
end
end
at_exit { t[:should_exit] = true }
t
end