Improved documentation

This commit is contained in:
Eduard Urbach 2023-07-18 09:40:58 +02:00
parent f006f0c407
commit 76af0f8db2
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
3 changed files with 7 additions and 1 deletions

View File

@ -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()

View File

@ -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)

View File

@ -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.