Class: Rosette::Core::CachedHeadSnapshotFactory
- Inherits:
-
HeadSnapshotFactory
- Object
- HeadSnapshotFactory
- Rosette::Core::CachedHeadSnapshotFactory
- Defined in:
- lib/rosette/core/snapshots/cached_head_snapshot_factory.rb
Overview
Takes head snapshots and caches the results. Take a look at ActiveSupport::Cache for a good set of cache stores that conform to the right interface.
Instance Attribute Summary collapse
-
#cache ⇒ #fetch
readonly
The cache store.
Attributes inherited from HeadSnapshotFactory
Instance Method Summary collapse
-
#initialize(cache) ⇒ CachedHeadSnapshotFactory
constructor
Creates a new cached head snapshot factory that uses the given cache.
Methods inherited from HeadSnapshotFactory
#set_repo_config, #take_snapshot
Constructor Details
#initialize(cache) ⇒ CachedHeadSnapshotFactory
Creates a new cached head snapshot factory that uses the given cache.
23 24 25 |
# File 'lib/rosette/core/snapshots/cached_head_snapshot_factory.rb', line 23 def initialize(cache) @cache = cache end |
Instance Attribute Details
#cache ⇒ #fetch (readonly)
Returns the cache store. This can be any object that responds to #fetch (and passes a block).
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rosette/core/snapshots/cached_head_snapshot_factory.rb', line 17 class CachedHeadSnapshotFactory < HeadSnapshotFactory attr_reader :cache # Creates a new cached head snapshot factory that uses the given cache. # # @param [#fetch] cache The cache to use. def initialize(cache) @cache = cache end protected def process_ref(rev_walk, ref) cache_key = head_snapshot_cache_key( repo_config.name, repo_config.repo.get_rev_commit(ref, rev_walk).getId.name ) cache.fetch(cache_key) do super end end def head_snapshot_cache_key(repo_name, commit_id) ['head_snapshots', repo_config.name, commit_id].join('/') end def head_snapshot_factory Rosette::Core::HeadSnapshotFactory end end |