cartodb-4.42/app/models/common_data/singleton.rb

22 lines
452 B
Ruby
Raw Normal View History

2024-04-06 13:25:13 +08:00
class CommonDataSingleton
include Singleton
def initialize
@common_data = nil
@last_usage = Time.now
end
def datasets(visualizations_api_url)
now = Time.now
if @common_data.nil? || (now - @last_usage > (cache_ttl * 60))
@common_data = CommonData.new(visualizations_api_url)
@last_usage = now
end
@common_data.datasets
end
def cache_ttl
Cartodb.get_config(:common_data, 'cache_ttl') || 0
end
end