Documentation ¶
Overview ¶
Package group provides a sample lazy load container. The group only creating a new object not until the object is needed by user. And it will cache all the objects to reduce the creation of object.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Group ¶
Group is a lazy load container.
func (*Group) Get ¶
Get gets the object by the given key.
Example ¶
new := func() interface{} { fmt.Println("Only Once") return &Counter{} } group := NewGroup(new) // Create a new Counter group.Get("pass").(*Counter).Incr() // Get the created Counter again. group.Get("pass").(*Counter).Incr()
Output: Only Once
func (*Group) Reset ¶
func (g *Group) Reset(new func() interface{})
Reset resets the new function and deletes all existing objects.
Example ¶
new := func() interface{} { return &Counter{} } group := NewGroup(new) newV2 := func() interface{} { fmt.Println("New V2") return &Counter{} } // Reset the new function and clear all created objects. group.Reset(newV2) // Create a new Counter group.Get("pass").(*Counter).Incr()
Output: New V2
Click to show internal directories.
Click to hide internal directories.