diff --git a/.gitignore b/.gitignore index 6398aa8..0766168 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ Gemfile.lock _yardoc doc/ .idea +Dockerfile diff --git a/README.md b/README.md index dfee151..e2cabc6 100644 --- a/README.md +++ b/README.md @@ -258,9 +258,6 @@ If there is a lot of events saved to an aggregate it can take some time to reloa There is one global snapshot store where all snapshots are stored independent on aggregate_type. To enable snapshot on a aggregate_type the Class has to be added to the `snapshot_types` Array when configuring Sandthorn. The aggregate will now be stored to the snapshot_store on every `.save` and when using `.find` it will look for a snapshot of the requested aggregate. -Currently its only possible to store the snapshots in memory, so be careful not draining your applications memory space. - - ```ruby class Board @@ -272,7 +269,7 @@ Sandthorn.configure do |c| end ``` -Its also possible to take manual snapshots without enabling snapshots on the aggregate_type. +Its possible to take manual snapshots without enabling snapshots on the aggregate_type. ```ruby board = Board.new @@ -285,6 +282,18 @@ Sandthorn.save_snapshot board snapshot = Sandthorn.find_snapshot board.aggregate_id ``` +### External snapshot store + +Currently there is no external snapshot stores available but this is how `Sandthorn` should be configured with one when there is. + +```ruby +Sandthorn.configure do |conf| + conf.snapshot_store = +end +``` + +**Currently its only possible to store the snapshots in the application memory (be careful not draining your application memory space).** + ## Bounded Context A bounded context is a system divider that split large systems into smaller parts. [Bounded Context by Martin Fowler](http://martinfowler.com/bliki/BoundedContext.html) diff --git a/lib/sandthorn.rb b/lib/sandthorn.rb index 07882e6..3dc7c22 100644 --- a/lib/sandthorn.rb +++ b/lib/sandthorn.rb @@ -2,7 +2,7 @@ require "sandthorn/errors" require "sandthorn/aggregate_root" require "sandthorn/event_stores" -require "sandthorn/snapshot_store" +require "sandthorn/application_snapshot_store" require 'yaml' require 'securerandom' @@ -83,8 +83,8 @@ def event_stores @event_stores ||= EventStores.new end - def event_store=(store) - @event_stores = EventStores.new(store) + def event_store=(event_store) + @event_stores = EventStores.new(event_store) end def map_types= data @@ -92,7 +92,11 @@ def map_types= data end def snapshot_store - @snapshot_store ||= SnapshotStore.new + @snapshot_store ||= ApplicationSnapshotStore.new + end + + def snapshot_store=(snapshot_store) + @snapshot_store = snapshot_store end def snapshot_types= aggregate_types diff --git a/lib/sandthorn/application_snapshot_store.rb b/lib/sandthorn/application_snapshot_store.rb new file mode 100644 index 0000000..35f6fbb --- /dev/null +++ b/lib/sandthorn/application_snapshot_store.rb @@ -0,0 +1,17 @@ +module Sandthorn + class ApplicationSnapshotStore + def initialize + @store = Hash.new + end + + attr_reader :store + + def save aggregate_id, aggregate + @store[aggregate_id] = aggregate + end + + def find aggregate_id + @store[aggregate_id] + end + end +end diff --git a/lib/sandthorn/snapshot_store.rb b/lib/sandthorn/snapshot_store.rb deleted file mode 100644 index cfba625..0000000 --- a/lib/sandthorn/snapshot_store.rb +++ /dev/null @@ -1,17 +0,0 @@ -module Sandthorn - class SnapshotStore - def initialize - @store = Hash.new - end - - attr_reader :store - - def save key, value - @store[key] = value - end - - def find key - @store[key] - end - end -end