Improved documentation
This commit is contained in:
parent
f006f0c407
commit
76af0f8db2
@ -7,6 +7,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Collection is the interface to access and modify your data.
|
||||||
type Collection[T any] interface {
|
type Collection[T any] interface {
|
||||||
All() <-chan *T
|
All() <-chan *T
|
||||||
Clear()
|
Clear()
|
||||||
|
@ -15,11 +15,13 @@ func TestFilePersistence(t *testing.T) {
|
|||||||
|
|
||||||
defer users.Clear()
|
defer users.Clear()
|
||||||
|
|
||||||
|
// Write data to disk
|
||||||
users.Set("1", &User{Name: "User 1"})
|
users.Set("1", &User{Name: "User 1"})
|
||||||
users.Set("2", &User{Name: "User 2"})
|
users.Set("2", &User{Name: "User 2"})
|
||||||
users.Set("3", &User{Name: "User 3"})
|
users.Set("3", &User{Name: "User 3"})
|
||||||
users.Sync()
|
users.Sync()
|
||||||
|
|
||||||
|
// Reload data from disk
|
||||||
reload, err := ocean.NewFile[User]("test")
|
reload, err := ocean.NewFile[User]("test")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
@ -55,6 +55,9 @@ BenchmarkNew-12 48838576 22.89 ns/op 80 B/op
|
|||||||
|
|
||||||
## Storage systems
|
## 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
|
### nil
|
||||||
|
|
||||||
You can specify `nil` as the storage system which will keep data in RAM only.
|
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:
|
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.
|
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.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user