Module: CacheAspect
- Included in:
- ServerBase
- Defined in:
- lib/macaw_framework/aspects/cache_aspect.rb
Overview
Aspect that provide cache for the endpoints.
Instance Method Summary collapse
Instance Method Details
#call_endpoint(cache, *args, **kwargs) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/macaw_framework/aspects/cache_aspect.rb', line 6 def call_endpoint(cache, *args, **kwargs) return super(*args, **kwargs) unless !cache[:cache].nil? && cache[:endpoints_to_cache]&.include?(args[0]) cache_filtered_name = cache_name_filter(args[1], cache[:cached_methods][args[0]]) cache[:cache].mutex.synchronize do return cache[:cache].cache[cache_filtered_name][0] unless cache[:cache].cache[cache_filtered_name].nil? response = super(*args, **kwargs) cache[:cache].cache[cache_filtered_name] = [response, Time.now] if should_cache_response?(response[1]) response end end |