diff --git a/Collection.go b/Collection.go index 3411b60..30fa6bd 100644 --- a/Collection.go +++ b/Collection.go @@ -7,6 +7,7 @@ import ( "sync" ) +// Collection is the interface to access and modify your data. type Collection[T any] interface { All() <-chan *T Clear() diff --git a/File_test.go b/File_test.go index 24cf118..22c563d 100644 --- a/File_test.go +++ b/File_test.go @@ -15,11 +15,13 @@ func TestFilePersistence(t *testing.T) { defer users.Clear() + // Write data to disk users.Set("1", &User{Name: "User 1"}) users.Set("2", &User{Name: "User 2"}) users.Set("3", &User{Name: "User 3"}) users.Sync() + // Reload data from disk reload, err := ocean.NewFile[User]("test") assert.Nil(t, err) diff --git a/README.md b/README.md index 99c8953..c609f88 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,9 @@ BenchmarkNew-12 48838576 22.89 ns/op 80 B/op ## Storage systems +When you initiate a new collection via `ocean.New` you can specify a storage system. +`ocean.NewFile` is a useful shortcut to create a collection with the `ocean.File` storage. + ### nil You can specify `nil` as the storage system which will keep data in RAM only. @@ -68,7 +71,7 @@ Every collection uses one goroutine to check the "dirty" flag, write the new con The biggest advantage of `ocean.File` is that it scales well with the number of requests: -Suppose `n` is the number of write requests and `io` is the time it takes for one write. Immediate ocean would require `O(n * io)` time to complete all writes but the async behavior makes it `O(n)`. +Suppose `n` is the number of write requests and `io` is the time it takes for one write. Immediate writes would require `O(n * io)` time to complete all writes but the async behavior makes it `O(n)`. You should use `ocean.File` if you have a permanently running process such as a web server where end users expect quick responses and background work can happen after the user request has already been dealt with.