Module: Roda::RodaPlugins::PerThreadCaching

Defined in:
lib/roda/plugins/per_thread_caching.rb

Overview

The per_thread_caching plugin changes the default cache from being a shared thread safe cache to a separate cache per thread. This means getting or setting values no longer needs a mutex on non-MRI ruby implementations, which may be faster when using a thread pool. However, since the caches are no longer shared, this will take up more memory.

Note that it does not make sense to use this plugin on MRI, since the default cache on MRI doesn’t use a mutex as it is already thread safe due to the GVL.

Using this plugin changes the matcher regexp cache to use per-thread caches, and changes the default for future thread-safe caches to use per-thread caches.

If you want the render plugin’s template cache to use per-thread caches, you should load this plugin before the render plugin.

Defined Under Namespace

Modules: ClassMethods Classes: Cache

Class Method Summary collapse

Class Method Details

.configure(app) ⇒ Object



22
23
24
# File 'lib/roda/plugins/per_thread_caching.rb', line 22

def self.configure(app)
  app::RodaRequest.match_pattern_cache = app.thread_safe_cache
end