Documentation ¶
Index ¶
- type Department
- type Employee
- type HRCache
- func (c *HRCache) Close() error
- func (c *HRCache) GetDepartment(ctx context.Context, deptName string) (*Department, error)
- func (c *HRCache) GetEmployee(ctx context.Context, id int) (*Employee, error)
- func (c *HRCache) GetOrg(ctx context.Context, orgName string) (*Org, error)
- func (c *HRCache) Stats() *Stats
- type HRDatabase
- type HRSystem
- type Org
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Department ¶
func (*Department) LogValue ¶
func (d *Department) LogValue() slog.Value
LogValue implements slog.LogValuer.
func (*Department) String ¶
func (d *Department) String() string
type Employee ¶
func (*Employee) LogValue ¶
LogValue implements slog.LogValuer.
type HRCache ¶
type HRCache struct {
// contains filtered or unexported fields
}
HRCache is a caching layer for any HRSystem implementation. HRCache is a composite cache, using a oncecache.Cache instance for each of the Org, Department, and Employee entity types. Using the oncecache event mechanism, a cache entry fill of one cache is propagated to other caches. For example, a call to HRCache.GetOrg populates not only that single cache entry, but propagates values to the Department cache, which in turn propagates values to the Employee cache.
func NewHRCache ¶
NewHRCache wraps db with a caching layer.
func (*HRCache) GetDepartment ¶
GetDepartment implements HRSystem.
func (*HRCache) GetEmployee ¶
GetEmployee implements HRSystem.
type HRDatabase ¶
type HRDatabase struct {
// contains filtered or unexported fields
}
HRDatabase pretends to be a database, but it's really just an in-memory structure loaded from a JSON file. It implements HRSystem.
func NewHRDatabase ¶
func NewHRDatabase(log *slog.Logger, datafile string) (*HRDatabase, error)
NewHRDatabase returns a new HRDatabase instance loaded from json datafile.
func (*HRDatabase) GetDepartment ¶
func (db *HRDatabase) GetDepartment(ctx context.Context, dept string) (*Department, error)
GetDepartment implements HRSystem.
func (*HRDatabase) GetEmployee ¶
GetEmployee implements HRSystem.
func (*HRDatabase) Stats ¶
func (db *HRDatabase) Stats() *Stats
Stats returns database invocation stats.
type Org ¶
type Org struct { Name string `json:"name"` Departments []*Department `json:"departments"` }
type Stats ¶
type Stats struct {
// contains filtered or unexported fields
}
Stats tracks how many times a method has been invoked.
func (*Stats) GetDepartment ¶
GetDepartment returns the number of times GetDepartment has been called.
func (*Stats) GetEmployee ¶
GetEmployee returns the number of times GetEmployee has been called.