From e6d44599928d181a6df1eb16cd522ebade53c80f Mon Sep 17 00:00:00 2001 From: John Date: Tue, 11 Jun 2019 20:57:43 +0800 Subject: [PATCH] comment update for gcache --- g/container/garray/garray_normal_int.go | 10 +- g/container/garray/garray_normal_interface.go | 8 +- g/container/garray/garray_normal_string.go | 10 +- g/container/garray/garray_sorted_int.go | 10 +- g/container/garray/garray_sorted_interface.go | 12 +- g/container/garray/garray_sorted_string.go | 10 +- g/container/gmap/gmap.go | 8 +- g/container/gmap/gmap_hash_any_any_map.go | 2 +- g/container/gmap/gmap_hash_int_any_map.go | 2 +- g/container/gmap/gmap_hash_int_int_map.go | 2 +- g/container/gmap/gmap_hash_int_str_map.go | 2 +- g/container/gmap/gmap_hash_str_any_map.go | 2 +- g/container/gmap/gmap_hash_str_int_map.go | 2 +- g/container/gmap/gmap_hash_str_str_map.go | 2 +- g/container/gmap/gmap_link_map.go | 2 +- g/container/gmap/gmap_tree_map.go | 4 +- g/container/gset/gset.go | 2 +- g/container/gset/gset_int_set.go | 2 +- g/container/gset/gset_string_set.go | 2 +- g/container/gtree/gtree_avltree.go | 4 +- g/container/gtree/gtree_btree.go | 4 +- g/container/gtree/gtree_redblacktree.go | 4 +- g/container/gvar/gvar.go | 10 +- g/database/gdb/gdb.go | 4 +- g/frame/gins/gins.go | 4 +- g/net/gtcp/gtcp_server.go | 6 +- g/os/gcache/gcache_cache.go | 2 + g/os/gcache/gcache_mem_cache.go | 130 ++++++++++-------- g/os/gcache/gcache_mem_cache_item.go | 5 +- g/os/gcache/gcache_mem_cache_lru.go | 62 +++++---- g/os/gcfg/gcfg.go | 4 +- g/os/gcfg/gcfg_instance.go | 2 +- g/os/genv/genv.go | 22 +-- g/os/gfcache/gfcache.go | 19 +-- g/os/glog/glog_api.go | 4 +- g/os/glog/glog_chaining.go | 2 +- g/os/glog/glog_logger_api.go | 4 +- g/os/glog/glog_logger_chaining.go | 2 +- g/os/grpool/grpool.go | 2 +- g/os/gspath/gspath_cache.go | 10 +- g/os/gview/gview.go | 2 +- g/os/gview/gview_doparse.go | 1 + g/os/gview/gview_instance.go | 2 +- g/test/gtest/gtest.go | 6 +- g/text/gregex/gregex_cache.go | 2 + geg/other/test.go | 8 +- 46 files changed, 225 insertions(+), 196 deletions(-) diff --git a/g/container/garray/garray_normal_int.go b/g/container/garray/garray_normal_int.go index 79fc49c10..21636b16b 100644 --- a/g/container/garray/garray_normal_int.go +++ b/g/container/garray/garray_normal_int.go @@ -22,14 +22,14 @@ type IntArray struct { } // NewIntArray creates and returns an empty array. -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewIntArray(unsafe...bool) *IntArray { return NewIntArraySize(0, 0, unsafe...) } // NewIntArraySize create and returns an array with given size and cap. -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewIntArraySize(size int, cap int, unsafe...bool) *IntArray { return &IntArray{ @@ -39,7 +39,7 @@ func NewIntArraySize(size int, cap int, unsafe...bool) *IntArray { } // NewIntArrayFrom creates and returns an array with given slice . -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewIntArrayFrom(array []int, unsafe...bool) *IntArray { return &IntArray{ @@ -49,7 +49,7 @@ func NewIntArrayFrom(array []int, unsafe...bool) *IntArray { } // NewIntArrayFromCopy creates and returns an array from a copy of given slice . -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewIntArrayFromCopy(array []int, unsafe...bool) *IntArray { newArray := make([]int, len(array)) @@ -110,7 +110,7 @@ func (a *IntArray) Sum() (sum int) { } // Sort sorts the array in increasing order. -// The param controls whether sort +// The parameter controls whether sort // in increasing order(default) or decreasing order func (a *IntArray) Sort(reverse...bool) *IntArray { a.mu.Lock() diff --git a/g/container/garray/garray_normal_interface.go b/g/container/garray/garray_normal_interface.go index 666ad067a..f7a342067 100644 --- a/g/container/garray/garray_normal_interface.go +++ b/g/container/garray/garray_normal_interface.go @@ -22,7 +22,7 @@ type Array struct { } // New creates and returns an empty array. -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func New(unsafe...bool) *Array { return NewArraySize(0, 0, unsafe...) @@ -34,7 +34,7 @@ func NewArray(unsafe...bool) *Array { } // NewArraySize create and returns an array with given size and cap. -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewArraySize(size int, cap int, unsafe...bool) *Array { return &Array{ @@ -54,7 +54,7 @@ func NewFromCopy(array []interface{}, unsafe...bool) *Array { } // NewArrayFrom creates and returns an array with given slice . -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewArrayFrom(array []interface{}, unsafe...bool) *Array { return &Array{ @@ -64,7 +64,7 @@ func NewArrayFrom(array []interface{}, unsafe...bool) *Array { } // NewArrayFromCopy creates and returns an array from a copy of given slice . -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewArrayFromCopy(array []interface{}, unsafe...bool) *Array { newArray := make([]interface{}, len(array)) diff --git a/g/container/garray/garray_normal_string.go b/g/container/garray/garray_normal_string.go index 0cd41b03c..dee581088 100644 --- a/g/container/garray/garray_normal_string.go +++ b/g/container/garray/garray_normal_string.go @@ -23,14 +23,14 @@ type StringArray struct { } // NewStringArray creates and returns an empty array. -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewStringArray(unsafe...bool) *StringArray { return NewStringArraySize(0, 0, unsafe...) } // NewStringArraySize create and returns an array with given size and cap. -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewStringArraySize(size int, cap int, unsafe...bool) *StringArray { return &StringArray{ @@ -40,7 +40,7 @@ func NewStringArraySize(size int, cap int, unsafe...bool) *StringArray { } // NewStringArrayFrom creates and returns an array with given slice . -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewStringArrayFrom(array []string, unsafe...bool) *StringArray { return &StringArray { @@ -50,7 +50,7 @@ func NewStringArrayFrom(array []string, unsafe...bool) *StringArray { } // NewStringArrayFromCopy creates and returns an array from a copy of given slice . -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewStringArrayFromCopy(array []string, unsafe...bool) *StringArray { newArray := make([]string, len(array)) @@ -111,7 +111,7 @@ func (a *StringArray) Sum() (sum int) { } // Sort sorts the array in increasing order. -// The param controls whether sort +// The parameter controls whether sort // in increasing order(default) or decreasing order func (a *StringArray) Sort(reverse...bool) *StringArray { a.mu.Lock() diff --git a/g/container/garray/garray_sorted_int.go b/g/container/garray/garray_sorted_int.go index 9288a0702..b3d0fbddc 100644 --- a/g/container/garray/garray_sorted_int.go +++ b/g/container/garray/garray_sorted_int.go @@ -26,14 +26,14 @@ type SortedIntArray struct { } // NewSortedIntArray creates and returns an empty sorted array. -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewSortedIntArray(unsafe...bool) *SortedIntArray { return NewSortedIntArraySize(0, unsafe...) } // NewSortedIntArraySize create and returns an sorted array with given size and cap. -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewSortedIntArraySize(cap int, unsafe...bool) *SortedIntArray { return &SortedIntArray { @@ -53,7 +53,7 @@ func NewSortedIntArraySize(cap int, unsafe...bool) *SortedIntArray { } // NewIntArrayFrom creates and returns an sorted array with given slice . -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewSortedIntArrayFrom(array []int, unsafe...bool) *SortedIntArray { a := NewSortedIntArraySize(0, unsafe...) @@ -63,7 +63,7 @@ func NewSortedIntArrayFrom(array []int, unsafe...bool) *SortedIntArray { } // NewSortedIntArrayFromCopy creates and returns an sorted array from a copy of given slice . -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewSortedIntArrayFromCopy(array []int, unsafe...bool) *SortedIntArray { newArray := make([]int, len(array)) @@ -84,7 +84,7 @@ func (a *SortedIntArray) SetArray(array []int) *SortedIntArray { } // Sort sorts the array in increasing order. -// The param controls whether sort +// The parameter controls whether sort // in increasing order(default) or decreasing order. func (a *SortedIntArray) Sort() *SortedIntArray { a.mu.Lock() diff --git a/g/container/garray/garray_sorted_interface.go b/g/container/garray/garray_sorted_interface.go index c392fc468..2181b3db2 100644 --- a/g/container/garray/garray_sorted_interface.go +++ b/g/container/garray/garray_sorted_interface.go @@ -26,8 +26,8 @@ type SortedArray struct { } // NewSortedArray creates and returns an empty sorted array. -// The param used to specify whether using array in un-concurrent-safety, which is false in default. -// The param used to compare values to sort in array, +// The parameter used to specify whether using array in un-concurrent-safety, which is false in default. +// The parameter used to compare values to sort in array, // if it returns value < 0, means v1 < v2; // if it returns value = 0, means v1 = v2; // if it returns value > 0, means v1 > v2; @@ -36,7 +36,7 @@ func NewSortedArray(comparator func(v1, v2 interface{}) int, unsafe...bool) *Sor } // NewSortedArraySize create and returns an sorted array with given size and cap. -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewSortedArraySize(cap int, comparator func(v1, v2 interface{}) int, unsafe...bool) *SortedArray { return &SortedArray{ @@ -48,7 +48,7 @@ func NewSortedArraySize(cap int, comparator func(v1, v2 interface{}) int, unsafe } // NewSortedArrayFrom creates and returns an sorted array with given slice . -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewSortedArrayFrom(array []interface{}, comparator func(v1, v2 interface{}) int, unsafe...bool) *SortedArray { a := NewSortedArraySize(0, comparator, unsafe...) @@ -60,7 +60,7 @@ func NewSortedArrayFrom(array []interface{}, comparator func(v1, v2 interface{}) } // NewSortedArrayFromCopy creates and returns an sorted array from a copy of given slice . -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewSortedArrayFromCopy(array []interface{}, unsafe...bool) *SortedArray { newArray := make([]interface{}, len(array)) @@ -83,7 +83,7 @@ func (a *SortedArray) SetArray(array []interface{}) *SortedArray { } // Sort sorts the array in increasing order. -// The param controls whether sort +// The parameter controls whether sort // in increasing order(default) or decreasing order func (a *SortedArray) Sort() *SortedArray { a.mu.Lock() diff --git a/g/container/garray/garray_sorted_string.go b/g/container/garray/garray_sorted_string.go index 28e7a2fa0..ec8ba4a3a 100644 --- a/g/container/garray/garray_sorted_string.go +++ b/g/container/garray/garray_sorted_string.go @@ -27,14 +27,14 @@ type SortedStringArray struct { } // NewSortedStringArray creates and returns an empty sorted array. -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewSortedStringArray(unsafe...bool) *SortedStringArray { return NewSortedStringArraySize(0, unsafe...) } // NewSortedStringArraySize create and returns an sorted array with given size and cap. -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewSortedStringArraySize(cap int, unsafe...bool) *SortedStringArray { return &SortedStringArray { @@ -48,7 +48,7 @@ func NewSortedStringArraySize(cap int, unsafe...bool) *SortedStringArray { } // NewSortedStringArrayFrom creates and returns an sorted array with given slice . -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewSortedStringArrayFrom(array []string, unsafe...bool) *SortedStringArray { a := NewSortedStringArraySize(0, unsafe...) @@ -58,7 +58,7 @@ func NewSortedStringArrayFrom(array []string, unsafe...bool) *SortedStringArray } // NewSortedStringArrayFromCopy creates and returns an sorted array from a copy of given slice . -// The param used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in un-concurrent-safety, // which is false in default. func NewSortedStringArrayFromCopy(array []string, unsafe...bool) *SortedStringArray { newArray := make([]string, len(array)) @@ -79,7 +79,7 @@ func (a *SortedStringArray) SetArray(array []string) *SortedStringArray { } // Sort sorts the array in increasing order. -// The param controls whether sort +// The parameter controls whether sort // in increasing order(default) or decreasing order. func (a *SortedStringArray) Sort() *SortedStringArray { a.mu.Lock() diff --git a/g/container/gmap/gmap.go b/g/container/gmap/gmap.go index 7ce4b9e87..10a013c9a 100644 --- a/g/container/gmap/gmap.go +++ b/g/container/gmap/gmap.go @@ -12,7 +12,7 @@ type Map = AnyAnyMap type HashMap = AnyAnyMap // New returns an empty hash map. -// The param used to specify whether using map in un-concurrent-safety, +// The parameter used to specify whether using map in un-concurrent-safety, // which is false in default, means concurrent-safe. func New(unsafe ...bool) *Map { return NewAnyAnyMap(unsafe...) @@ -21,14 +21,14 @@ func New(unsafe ...bool) *Map { // NewFrom returns a hash map from given map . // Note that, the param map will be set as the underlying data map(no deep copy), // there might be some concurrent-safe issues when changing the map outside. -// The param used to specify whether using tree in un-concurrent-safety, +// The parameter used to specify whether using tree in un-concurrent-safety, // which is false in default. func NewFrom(data map[interface{}]interface{}, unsafe...bool) *Map { return NewAnyAnyMapFrom(data, unsafe...) } // NewHashMap returns an empty hash map. -// The param used to specify whether using map in un-concurrent-safety, +// The parameter used to specify whether using map in un-concurrent-safety, // which is false in default, means concurrent-safe. func NewHashMap(unsafe ...bool) *Map { return NewAnyAnyMap(unsafe...) @@ -37,7 +37,7 @@ func NewHashMap(unsafe ...bool) *Map { // NewHashMapFrom returns a hash map from given map . // Note that, the param map will be set as the underlying data map(no deep copy), // there might be some concurrent-safe issues when changing the map outside. -// The param used to specify whether using tree in un-concurrent-safety, +// The parameter used to specify whether using tree in un-concurrent-safety, // which is false in default. func NewHashMapFrom(data map[interface{}]interface{}, unsafe...bool) *Map { return NewAnyAnyMapFrom(data, unsafe...) diff --git a/g/container/gmap/gmap_hash_any_any_map.go b/g/container/gmap/gmap_hash_any_any_map.go index db7d217c0..09d39a3c2 100644 --- a/g/container/gmap/gmap_hash_any_any_map.go +++ b/g/container/gmap/gmap_hash_any_any_map.go @@ -17,7 +17,7 @@ type AnyAnyMap struct { } // NewAnyAnyMap returns an empty hash map. -// The param used to specify whether using map in un-concurrent-safety, +// The parameter used to specify whether using map in un-concurrent-safety, // which is false in default, means concurrent-safe. func NewAnyAnyMap(unsafe ...bool) *AnyAnyMap { return &AnyAnyMap{ diff --git a/g/container/gmap/gmap_hash_int_any_map.go b/g/container/gmap/gmap_hash_int_any_map.go index 1be1c9229..ea4c745e0 100644 --- a/g/container/gmap/gmap_hash_int_any_map.go +++ b/g/container/gmap/gmap_hash_int_any_map.go @@ -19,7 +19,7 @@ type IntAnyMap struct { } // NewIntAnyMap returns an empty IntAnyMap object. -// The param used to specify whether using map in un-concurrent-safety, +// The parameter used to specify whether using map in un-concurrent-safety, // which is false in default, means concurrent-safe. func NewIntAnyMap(unsafe...bool) *IntAnyMap { return &IntAnyMap{ diff --git a/g/container/gmap/gmap_hash_int_int_map.go b/g/container/gmap/gmap_hash_int_int_map.go index 1be07f266..132a336f3 100644 --- a/g/container/gmap/gmap_hash_int_int_map.go +++ b/g/container/gmap/gmap_hash_int_int_map.go @@ -16,7 +16,7 @@ type IntIntMap struct { } // NewIntIntMap returns an empty IntIntMap object. -// The param used to specify whether using map in un-concurrent-safety, +// The parameter used to specify whether using map in un-concurrent-safety, // which is false in default, means concurrent-safe. func NewIntIntMap(unsafe...bool) *IntIntMap { return &IntIntMap{ diff --git a/g/container/gmap/gmap_hash_int_str_map.go b/g/container/gmap/gmap_hash_int_str_map.go index 3c985d1ac..b5e241b01 100644 --- a/g/container/gmap/gmap_hash_int_str_map.go +++ b/g/container/gmap/gmap_hash_int_str_map.go @@ -17,7 +17,7 @@ type IntStrMap struct { } // NewIntStrMap returns an empty IntStrMap object. -// The param used to specify whether using map in un-concurrent-safety, +// The parameter used to specify whether using map in un-concurrent-safety, // which is false in default, means concurrent-safe. func NewIntStrMap(unsafe ...bool) *IntStrMap { return &IntStrMap{ diff --git a/g/container/gmap/gmap_hash_str_any_map.go b/g/container/gmap/gmap_hash_str_any_map.go index 6fe1884ed..bb1ca7f6d 100644 --- a/g/container/gmap/gmap_hash_str_any_map.go +++ b/g/container/gmap/gmap_hash_str_any_map.go @@ -19,7 +19,7 @@ type StrAnyMap struct { } // NewStrAnyMap returns an empty StrAnyMap object. -// The param used to specify whether using map in un-concurrent-safety, +// The parameter used to specify whether using map in un-concurrent-safety, // which is false in default, means concurrent-safe. func NewStrAnyMap(unsafe ...bool) *StrAnyMap { return &StrAnyMap{ diff --git a/g/container/gmap/gmap_hash_str_int_map.go b/g/container/gmap/gmap_hash_str_int_map.go index d2ff6c0f3..3541f3904 100644 --- a/g/container/gmap/gmap_hash_str_int_map.go +++ b/g/container/gmap/gmap_hash_str_int_map.go @@ -18,7 +18,7 @@ type StrIntMap struct { } // NewStrIntMap returns an empty StrIntMap object. -// The param used to specify whether using map in un-concurrent-safety, +// The parameter used to specify whether using map in un-concurrent-safety, // which is false in default, means concurrent-safe. func NewStrIntMap(unsafe ...bool) *StrIntMap { return &StrIntMap{ diff --git a/g/container/gmap/gmap_hash_str_str_map.go b/g/container/gmap/gmap_hash_str_str_map.go index 143f103fb..6d0b6dab3 100644 --- a/g/container/gmap/gmap_hash_str_str_map.go +++ b/g/container/gmap/gmap_hash_str_str_map.go @@ -17,7 +17,7 @@ type StrStrMap struct { } // NewStrStrMap returns an empty StrStrMap object. -// The param used to specify whether using map in un-concurrent-safety, +// The parameter used to specify whether using map in un-concurrent-safety, // which is false in default, means concurrent-safe. func NewStrStrMap(unsafe...bool) *StrStrMap { return &StrStrMap{ diff --git a/g/container/gmap/gmap_link_map.go b/g/container/gmap/gmap_link_map.go index 886225cbd..6f78d648c 100644 --- a/g/container/gmap/gmap_link_map.go +++ b/g/container/gmap/gmap_link_map.go @@ -25,7 +25,7 @@ type gListMapNode struct { // NewListMap returns an empty link map. // ListMap is backed by a hash table to store values and doubly-linked list to store ordering. -// The param used to specify whether using map in un-concurrent-safety, +// The parameter used to specify whether using map in un-concurrent-safety, // which is false in default, means concurrent-safe. func NewListMap(unsafe ...bool) *ListMap { return &ListMap{ diff --git a/g/container/gmap/gmap_tree_map.go b/g/container/gmap/gmap_tree_map.go index 7e91f4b49..73c973ef4 100644 --- a/g/container/gmap/gmap_tree_map.go +++ b/g/container/gmap/gmap_tree_map.go @@ -14,7 +14,7 @@ import ( type TreeMap = gtree.RedBlackTree // NewTreeMap instantiates a tree map with the custom comparator. -// The param used to specify whether using tree in un-concurrent-safety, +// The parameter used to specify whether using tree in un-concurrent-safety, // which is false in default. func NewTreeMap(comparator func(v1, v2 interface{}) int, unsafe...bool) *TreeMap { return gtree.NewRedBlackTree(comparator, unsafe...) @@ -23,7 +23,7 @@ func NewTreeMap(comparator func(v1, v2 interface{}) int, unsafe...bool) *TreeMap // NewTreeMapFrom instantiates a tree map with the custom comparator and map. // Note that, the param map will be set as the underlying data map(no deep copy), // there might be some concurrent-safe issues when changing the map outside. -// The param used to specify whether using tree in un-concurrent-safety, +// The parameter used to specify whether using tree in un-concurrent-safety, // which is false in default. func NewTreeMapFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, unsafe...bool) *TreeMap { return gtree.NewRedBlackTreeFrom(comparator, data, unsafe...) diff --git a/g/container/gset/gset.go b/g/container/gset/gset.go index 8c02bd33b..de1461e6e 100644 --- a/g/container/gset/gset.go +++ b/g/container/gset/gset.go @@ -19,7 +19,7 @@ type Set struct { } // New create and returns a new set, which contains un-repeated items. -// The param used to specify whether using set in un-concurrent-safety, +// The parameter used to specify whether using set in un-concurrent-safety, // which is false in default. func New(unsafe...bool) *Set { return NewSet(unsafe...) diff --git a/g/container/gset/gset_int_set.go b/g/container/gset/gset_int_set.go index 338952ff8..be0ee3cdf 100644 --- a/g/container/gset/gset_int_set.go +++ b/g/container/gset/gset_int_set.go @@ -19,7 +19,7 @@ type IntSet struct { } // New create and returns a new set, which contains un-repeated items. -// The param used to specify whether using set in un-concurrent-safety, +// The parameter used to specify whether using set in un-concurrent-safety, // which is false in default. func NewIntSet(unsafe...bool) *IntSet { return &IntSet{ diff --git a/g/container/gset/gset_string_set.go b/g/container/gset/gset_string_set.go index 7a5d20da4..6586cb8da 100644 --- a/g/container/gset/gset_string_set.go +++ b/g/container/gset/gset_string_set.go @@ -19,7 +19,7 @@ type StringSet struct { } // New create and returns a new set, which contains un-repeated items. -// The param used to specify whether using set in un-concurrent-safety, +// The parameter used to specify whether using set in un-concurrent-safety, // which is false in default. func NewStringSet(unsafe...bool) *StringSet { return &StringSet { diff --git a/g/container/gtree/gtree_avltree.go b/g/container/gtree/gtree_avltree.go index f6833871e..7c67bc25f 100644 --- a/g/container/gtree/gtree_avltree.go +++ b/g/container/gtree/gtree_avltree.go @@ -30,7 +30,7 @@ type AVLTreeNode struct { } // NewAVLTree instantiates an AVL tree with the custom comparator. -// The param used to specify whether using tree in un-concurrent-safety, +// The parameter used to specify whether using tree in un-concurrent-safety, // which is false in default. func NewAVLTree(comparator func(v1, v2 interface{}) int, unsafe...bool) *AVLTree { return &AVLTree{ @@ -40,7 +40,7 @@ func NewAVLTree(comparator func(v1, v2 interface{}) int, unsafe...bool) *AVLTree } // NewAVLTreeFrom instantiates an AVL tree with the custom comparator and data map. -// The param used to specify whether using tree in un-concurrent-safety, +// The parameter used to specify whether using tree in un-concurrent-safety, // which is false in default. func NewAVLTreeFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, unsafe...bool) *AVLTree { tree := NewAVLTree(comparator, unsafe...) diff --git a/g/container/gtree/gtree_btree.go b/g/container/gtree/gtree_btree.go index 57fd061f3..de4546cca 100644 --- a/g/container/gtree/gtree_btree.go +++ b/g/container/gtree/gtree_btree.go @@ -37,7 +37,7 @@ type BTreeEntry struct { } // NewBTree instantiates a B-tree with (maximum number of children) and a custom key comparator. -// The param used to specify whether using tree in un-concurrent-safety, +// The parameter used to specify whether using tree in un-concurrent-safety, // which is false in default. // Note that the must be greater or equal than 3, or else it panics. func NewBTree(m int, comparator func(v1, v2 interface{}) int, unsafe...bool) *BTree { @@ -52,7 +52,7 @@ func NewBTree(m int, comparator func(v1, v2 interface{}) int, unsafe...bool) *BT } // NewBTreeFrom instantiates a B-tree with (maximum number of children), a custom key comparator and data map. -// The param used to specify whether using tree in un-concurrent-safety, +// The parameter used to specify whether using tree in un-concurrent-safety, // which is false in default. func NewBTreeFrom(m int, comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, unsafe...bool) *BTree { tree := NewBTree(m, comparator, unsafe...) diff --git a/g/container/gtree/gtree_redblacktree.go b/g/container/gtree/gtree_redblacktree.go index ed8d16bf4..064b1ac63 100644 --- a/g/container/gtree/gtree_redblacktree.go +++ b/g/container/gtree/gtree_redblacktree.go @@ -37,7 +37,7 @@ type RedBlackTreeNode struct { } // NewRedBlackTree instantiates a red-black tree with the custom comparator. -// The param used to specify whether using tree in un-concurrent-safety, +// The parameter used to specify whether using tree in un-concurrent-safety, // which is false in default. func NewRedBlackTree(comparator func(v1, v2 interface{}) int, unsafe...bool) *RedBlackTree { return &RedBlackTree { @@ -47,7 +47,7 @@ func NewRedBlackTree(comparator func(v1, v2 interface{}) int, unsafe...bool) *Re } // NewRedBlackTreeFrom instantiates a red-black tree with the custom comparator and map. -// The param used to specify whether using tree in un-concurrent-safety, +// The parameter used to specify whether using tree in un-concurrent-safety, // which is false in default. func NewRedBlackTreeFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, unsafe...bool) *RedBlackTree { tree := NewRedBlackTree(comparator, unsafe...) diff --git a/g/container/gvar/gvar.go b/g/container/gvar/gvar.go index 62e2ea20a..728fe2570 100644 --- a/g/container/gvar/gvar.go +++ b/g/container/gvar/gvar.go @@ -20,7 +20,7 @@ type Var struct { } // New returns a new Var with given . -// The param used to specify whether using Var in un-concurrent-safety, +// The parameter used to specify whether using Var in un-concurrent-safety, // which is false in default, means concurrent-safe. func New(value interface{}, unsafe...bool) *Var { v := &Var{} @@ -59,7 +59,7 @@ func (v *Var) Interface() interface{} { } // Time converts and returns as time.Time. -// The param specifies the format of the time string using gtime, +// The parameter specifies the format of the time string using gtime, // eg: Y-m-d H:i:s. func (v *Var) Time(format...string) time.Time { return gconv.Time(v.Val(), format...) @@ -72,15 +72,15 @@ func (v *Var) Duration() time.Duration { } // GTime converts and returns as *gtime.Time. -// The param specifies the format of the time string using gtime, +// The parameter specifies the format of the time string using gtime, // eg: Y-m-d H:i:s. func (v *Var) GTime(format...string) *gtime.Time { return gconv.GTime(v.Val(), format...) } // Struct maps value of to . -// The param should be a pointer to a struct instance. -// The param is used to specify the key-to-attribute mapping rules. +// The parameter should be a pointer to a struct instance. +// The parameter is used to specify the key-to-attribute mapping rules. func (v *Var) Struct(pointer interface{}, mapping...map[string]string) error { return gconv.Struct(v.Val(), pointer, mapping...) } diff --git a/g/database/gdb/gdb.go b/g/database/gdb/gdb.go index 68a069344..51ccff12a 100644 --- a/g/database/gdb/gdb.go +++ b/g/database/gdb/gdb.go @@ -162,7 +162,7 @@ var ( ) // New creates ORM DB object with global configurations. -// The param specifies the configuration group name, +// The parameter specifies the configuration group name, // which is DEFAULT_GROUP_NAME in default. func New(name ...string) (db DB, err error) { group := configs.defaultGroup @@ -210,7 +210,7 @@ func New(name ...string) (db DB, err error) { } // Instance returns an instance for DB operations. -// The param specifies the configuration group name, +// The parameter specifies the configuration group name, // which is DEFAULT_GROUP_NAME in default. func Instance(name ...string) (db DB, err error) { group := configs.defaultGroup diff --git a/g/frame/gins/gins.go b/g/frame/gins/gins.go index e055ac72d..d689e2ef5 100644 --- a/g/frame/gins/gins.go +++ b/g/frame/gins/gins.go @@ -61,13 +61,13 @@ func SetIfNotExist(key string, value interface{}) bool { } // View returns an instance of View with default settings. -// The param is the name for the instance. +// The parameter is the name for the instance. func View(name ...string) *gview.View { return gview.Instance(name ...) } // Config returns an instance of View with default settings. -// The param is the name for the instance. +// The parameter is the name for the instance. func Config(name ...string) *gcfg.Config { return gcfg.Instance(name ...) } diff --git a/g/net/gtcp/gtcp_server.go b/g/net/gtcp/gtcp_server.go index f254d87ad..271b8e7b0 100644 --- a/g/net/gtcp/gtcp_server.go +++ b/g/net/gtcp/gtcp_server.go @@ -45,7 +45,7 @@ func GetServer(name...interface{}) *Server { } // NewServer creates and returns a new normal TCP server. -// The param is optional, which is used to specify the instance name of the server. +// The parameter is optional, which is used to specify the instance name of the server. func NewServer(address string, handler func (*Conn), name...string) *Server { s := &Server{ address : address, @@ -58,7 +58,7 @@ func NewServer(address string, handler func (*Conn), name...string) *Server { } // NewServerTLS creates and returns a new TCP server with TLS support. -// The param is optional, which is used to specify the instance name of the server. +// The parameter is optional, which is used to specify the instance name of the server. func NewServerTLS(address string, tlsConfig *tls.Config, handler func (*Conn), name...string) *Server { s := NewServer(address, handler, name...) s.SetTLSConfig(tlsConfig) @@ -66,7 +66,7 @@ func NewServerTLS(address string, tlsConfig *tls.Config, handler func (*Conn), n } // NewServerKeyCrt creates and returns a new TCP server with TLS support. -// The param is optional, which is used to specify the instance name of the server. +// The parameter is optional, which is used to specify the instance name of the server. func NewServerKeyCrt(address, crtFile, keyFile string, handler func (*Conn), name...string) *Server { s := NewServer(address, handler, name...) if err := s.SetTLSKeyCrt(crtFile, keyFile); err != nil { diff --git a/g/os/gcache/gcache_cache.go b/g/os/gcache/gcache_cache.go index e4456a9db..43466c8b0 100644 --- a/g/os/gcache/gcache_cache.go +++ b/g/os/gcache/gcache_cache.go @@ -29,6 +29,8 @@ func New(lruCap...int) *Cache { // Clear clears all data of the cache. func (c *Cache) Clear() { + // atomic swap to ensure atomicity. old := atomic.SwapPointer((*unsafe.Pointer)(unsafe.Pointer(&c.memCache)), unsafe.Pointer(newMemCache())) + // close the old cache object. (*memCache)(old).Close() } \ No newline at end of file diff --git a/g/os/gcache/gcache_mem_cache.go b/g/os/gcache/gcache_mem_cache.go index 0c4491dca..3de2d5071 100644 --- a/g/os/gcache/gcache_mem_cache.go +++ b/g/os/gcache/gcache_mem_cache.go @@ -39,24 +39,25 @@ type memCache struct { closed *gtype.Bool // Is this cache closed or not. } -// 缓存数据项 +// Internal cache item. type memCacheItem struct { - v interface{} // 键值 - e int64 // 过期时间 + v interface{} // Value. + e int64 // Expire time in milliseconds. } -// 异步队列数据项 +// Internal event item. type memCacheEvent struct { - k interface{} // 键名 - e int64 // 过期时间 + k interface{} // Key. + e int64 // Expire time in milliseconds. } const ( - // 当数据不过期时,默认设置的过期属性值,相当于:math.MaxInt64/1000000 + // Default expire time for no expiring items. + // It equals to math.MaxInt64/1000000. gDEFAULT_MAX_EXPIRE = 9223372036854 ) -// 创建底层的缓存对象 +// newMemCache creates and returns a new memory cache object. func newMemCache(lruCap...int) *memCache { c := &memCache { lruGetList : glist.New(), @@ -73,12 +74,12 @@ func newMemCache(lruCap...int) *memCache { return c } -// 计算过期缓存的键名(将毫秒换算成秒的整数毫秒,按照1秒进行分组) +// makeExpireKey groups the in milliseconds to its according seconds. func (c *memCache) makeExpireKey(expire int64) int64 { return int64(math.Ceil(float64(expire/1000) + 1)*1000) } -// 获取一个过期键名存放Set, 如果没有则返回nil +// getExpireSet returns the expire set for given in seconds. func (c *memCache) getExpireSet(expire int64) (expireSet *gset.Set) { c.expireSetMu.RLock() expireSet, _ = c.expireSets[expire] @@ -86,23 +87,19 @@ func (c *memCache) getExpireSet(expire int64) (expireSet *gset.Set) { return } -// 获取或者创建一个过期键名存放Set(由于是异步单线程执行,因此不会出现创建set时的覆盖问题) +// getOrNewExpireSet returns the expire set for given in seconds. +// It creates and returns a new set for if it does not exist. func (c *memCache) getOrNewExpireSet(expire int64) (expireSet *gset.Set) { if expireSet = c.getExpireSet(expire); expireSet == nil { - expireSet = gset.New() c.expireSetMu.Lock() - // 写锁二次检索确认 - if es, ok := c.expireSets[expire]; ok { - expireSet = es - } else { - c.expireSets[expire] = expireSet - } + c.expireSets[expire] = gset.New() c.expireSetMu.Unlock() } return } -// 设置kv缓存键值对,过期时间单位为毫秒,expire<=0表示不过期 +// Set sets cache with - pair, which is expired after milliseconds. +// If <=0 means it does not expire. func (c *memCache) Set(key interface{}, value interface{}, expire int) { expireTime := c.getInternalExpire(expire) c.dataMu.Lock() @@ -111,8 +108,12 @@ func (c *memCache) Set(key interface{}, value interface{}, expire int) { c.eventList.PushBack(&memCacheEvent{k : key, e : expireTime}) } -// 设置kv缓存键值对,内部会对键名的存在性使用写锁进行二次检索确认,如果存在则不再写入;返回键名对应的键值。 -// 在高并发下有用,防止数据写入的并发逻辑错误。 +// doSetWithLockCheck sets cache with - pair if does not exist in the cache, +// which is expired after milliseconds. +// If <=0 means it does not expire. +// +// It doubly checks the whether exists in the cache using mutex writing lock +// before setting it to the cache. func (c *memCache) doSetWithLockCheck(key interface{}, value interface{}, expire int) interface{} { expireTimestamp := c.getInternalExpire(expire) c.dataMu.Lock() @@ -132,7 +133,7 @@ func (c *memCache) doSetWithLockCheck(key interface{}, value interface{}, expire return value } -// 根据给定expire参数计算内部使用的expire过期时间 +// getInternalExpire returns the expire time with given expire duration in milliseconds. func (c *memCache) getInternalExpire(expire int) int64 { if expire != 0 { return gtime.Millisecond() + int64(expire) @@ -141,7 +142,9 @@ func (c *memCache) getInternalExpire(expire int) int64 { } } -// 当键名不存在时写入,并返回true;否则返回false。 +// SetIfNotExist sets cache with - pair if does not exist in the cache, +// which is expired after milliseconds. +// If <=0 means it does not expire. func (c *memCache) SetIfNotExist(key interface{}, value interface{}, expire int) bool { if !c.Contains(key) { c.doSetWithLockCheck(key, value, expire) @@ -150,7 +153,8 @@ func (c *memCache) SetIfNotExist(key interface{}, value interface{}, expire int) return false } -// 批量设置 +// Sets batch sets cache with key-value pairs by , which is expired after milliseconds. +// If <=0 means it does not expire. func (c *memCache) Sets(data map[interface{}]interface{}, expire int) { expireTime := c.getInternalExpire(expire) for k, v := range data { @@ -161,13 +165,14 @@ func (c *memCache) Sets(data map[interface{}]interface{}, expire int) { } } -// 获取指定键名的值 +// Get returns the value of . +// It returns nil if it does not exist or its value is nil. func (c *memCache) Get(key interface{}) interface{} { c.dataMu.RLock() item, ok := c.data[key] c.dataMu.RUnlock() if ok && !item.IsExpired() { - // 增加LRU(Least Recently Used)操作记录 + // Adding to LRU history if LRU feature is enbaled. if c.cap > 0 { c.lruGetList.PushBack(key) } @@ -176,7 +181,10 @@ func (c *memCache) Get(key interface{}) interface{} { return nil } -// 当键名存在时返回其键值,否则写入指定的键值 +// GetOrSet returns the value of , +// or sets - pair and returns if does not exist in the cache. +// The key-value pair expires after milliseconds. +// If <=0 means it does not expire. func (c *memCache) GetOrSet(key interface{}, value interface{}, expire int) interface{} { if v := c.Get(key); v == nil { return c.doSetWithLockCheck(key, value, expire) @@ -185,17 +193,26 @@ func (c *memCache) GetOrSet(key interface{}, value interface{}, expire int) inte } } -// 当键名存在时返回其键值,否则写入指定的键值,键值由指定的函数生成 +// GetOrSetFunc returns the value of , +// or sets with result of function and returns its result +// if does not exist in the cache. +// The key-value pair expires after milliseconds. +// If <=0 means it does not expire. func (c *memCache) GetOrSetFunc(key interface{}, f func() interface{}, expire int) interface{} { if v := c.Get(key); v == nil { - // 可能存在多个goroutine被阻塞在这里,f可能是并发运行 return c.doSetWithLockCheck(key, f(), expire) } else { return v } } -// 与GetOrSetFunc不同的是,f是在写锁机制内执行 +// GetOrSetFuncLock returns the value of , +// or sets with result of function and returns its result +// if does not exist in the cache. +// The key-value pair expires after milliseconds. +// If <=0 means it does not expire. +// +// Note that the function is executed within writing mutex lock. func (c *memCache) GetOrSetFuncLock(key interface{}, f func() interface{}, expire int) interface{} { if v := c.Get(key); v == nil { return c.doSetWithLockCheck(key, f, expire) @@ -204,12 +221,12 @@ func (c *memCache) GetOrSetFuncLock(key interface{}, f func() interface{}, expir } } -// 是否存在指定的键名,true表示存在,false表示不存在。 +// Contains returns true if exists in the cache, or else returns false. func (c *memCache) Contains(key interface{}) bool { return c.Get(key) != nil } -// 删除指定键值对,并返回被删除的键值 +// Remove deletes the in the cache, and returns its value. func (c *memCache) Remove(key interface{}) (value interface{}) { c.dataMu.RLock() item, ok := c.data[key] @@ -224,14 +241,14 @@ func (c *memCache) Remove(key interface{}) (value interface{}) { return } -// 批量删除键值对,并返回被删除的键值对数据 +// Removes deletes in the cache. func (c *memCache) Removes(keys []interface{}) { for _, key := range keys { c.Remove(key) } } -// 返回缓存的所有数据键值对(不包含已过期数据) +// Data returns a copy of all key-value pairs in the cache as map type. func (c *memCache) Data() map[interface{}]interface{} { m := make(map[interface{}]interface{}) c.dataMu.RLock() @@ -244,7 +261,7 @@ func (c *memCache) Data() map[interface{}]interface{} { return m } -// 获得所有的键名,组成数组返回 +// Keys returns all keys in the cache as slice. func (c *memCache) Keys() []interface{} { keys := make([]interface{}, 0) c.dataMu.RLock() @@ -257,12 +274,12 @@ func (c *memCache) Keys() []interface{} { return keys } -// 获得所有的键名,组成字符串数组返回 +// KeyStrings returns all keys in the cache as string slice. func (c *memCache) KeyStrings() []string { return gconv.Strings(c.Keys()) } -// 获得所有的值,组成数组返回 +// Values returns all values in the cache as slice. func (c *memCache) Values() []interface{} { values := make([]interface{}, 0) c.dataMu.RLock() @@ -275,7 +292,7 @@ func (c *memCache) Values() []interface{} { return values } -// 获得缓存对象的键值对数量 +// Size returns the size of the cache. func (c *memCache) Size() (size int) { c.dataMu.RLock() size = len(c.data) @@ -283,7 +300,7 @@ func (c *memCache) Size() (size int) { return } -// 删除缓存对象 +// Close closes the cache. func (c *memCache) Close() { if c.cap > 0 { c.lru.Close() @@ -291,9 +308,10 @@ func (c *memCache) Close() { c.closed.Set(true) } -// 数据异步任务循环: -// 1、将事件列表中的数据异步处理,并同步结果到expireTimes和expireSets属性中; -// 2、清理过期键值对数据; +// Asynchronous task loop: +// 1. asynchronously process the data in the event list, +// and synchronize the results to the and properties. +// 2. clean up the expired key-value pair data. func (c *memCache) syncEventAndClearExpired() { event := (*memCacheEvent)(nil) oldExpireTime := int64(0) @@ -303,7 +321,7 @@ func (c *memCache) syncEventAndClearExpired() { return } // ======================== - // 数据同步处理 + // Data Synchronization. // ======================== for { v := c.eventList.PopFront() @@ -311,28 +329,28 @@ func (c *memCache) syncEventAndClearExpired() { break } event = v.(*memCacheEvent) - // 获得旧的过期时间分组 + // Fetching the old expire set. c.expireTimeMu.RLock() oldExpireTime = c.expireTimes[event.k] c.expireTimeMu.RUnlock() - // 计算新的过期时间分组 + // Calculating the new expire set. newExpireTime = c.makeExpireKey(event.e) if newExpireTime != oldExpireTime { c.getOrNewExpireSet(newExpireTime).Add(event.k) if oldExpireTime != 0 { c.getOrNewExpireSet(oldExpireTime).Remove(event.k) } - // 重新设置对应键名的过期时间 + // Updating the expire time for . c.expireTimeMu.Lock() c.expireTimes[event.k] = newExpireTime c.expireTimeMu.Unlock() } - // 写入操作也会增加到LRU(Least Recently Used)操作记录 + // Adding the key the LRU history by writing operations. if c.cap > 0 { c.lru.Push(event.k) } } - // 异步处理读取操作的LRU列表 + // Processing expired keys from LRU. if c.cap > 0 && c.lruGetList.Len() > 0 { for { if v := c.lruGetList.PopFront(); v != nil { @@ -343,18 +361,18 @@ func (c *memCache) syncEventAndClearExpired() { } } // ======================== - // 缓存过期处理 + // Data Cleaning up. // ======================== ek := c.makeExpireKey(gtime.Millisecond()) eks := []int64{ek - 1000, ek - 2000, ek - 3000, ek - 4000, ek - 5000} for _, expireTime := range eks { if expireSet := c.getExpireSet(expireTime); expireSet != nil { - // 遍历Set,执行数据过期删除 + // Iterating the set to delete all keys in it. expireSet.Iterator(func(key interface{}) bool { c.clearByKey(key) return true }) - // Set数据处理完之后删除该Set + // Deleting the set after all of its keys are deleted. c.expireSetMu.Lock() delete(c.expireSets, expireTime) c.expireSetMu.Unlock() @@ -362,22 +380,22 @@ func (c *memCache) syncEventAndClearExpired() { } } -// 删除对应键名的缓存数据 +// clearByKey deletes the key-value pair with given . +// The parameter specifies whether doing this deleting forcely. func (c *memCache) clearByKey(key interface{}, force...bool) { - // 删除缓存数据 c.dataMu.Lock() - // 删除核对,真正的过期才删除 + // Doubly check before really deleting it from cache. if item, ok := c.data[key]; (ok && item.IsExpired()) || (len(force) > 0 && force[0]) { delete(c.data, key) } c.dataMu.Unlock() - // 删除异步处理数据项 + // Deleting its expire time from . c.expireTimeMu.Lock() delete(c.expireTimes, key) c.expireTimeMu.Unlock() - // 删除LRU管理对象中指定键名 + // Deleting it from LRU. if c.cap > 0 { c.lru.Remove(key) } diff --git a/g/os/gcache/gcache_mem_cache_item.go b/g/os/gcache/gcache_mem_cache_item.go index 72f9d1572..3735c4f70 100644 --- a/g/os/gcache/gcache_mem_cache_item.go +++ b/g/os/gcache/gcache_mem_cache_item.go @@ -8,9 +8,10 @@ package gcache import "github.com/gogf/gf/g/os/gtime" -// 判断缓存项是否已过期 +// IsExpired checks whether is expired. func (item *memCacheItem) IsExpired() bool { - // 注意这里应当包含等于,试想一下缓存时间只有最小粒度为1毫秒的情况 + // Note that it should use greater than or equal judgement here + // imagining that the cache time is only 1 millisecond. if item.e >= gtime.Millisecond() { return false } diff --git a/g/os/gcache/gcache_mem_cache_lru.go b/g/os/gcache/gcache_mem_cache_lru.go index 38fa2e2b0..196e387ba 100644 --- a/g/os/gcache/gcache_mem_cache_lru.go +++ b/g/os/gcache/gcache_mem_cache_lru.go @@ -7,24 +7,24 @@ package gcache import ( - "fmt" - "github.com/gogf/gf/g/container/glist" - "github.com/gogf/gf/g/container/gmap" - "github.com/gogf/gf/g/container/gtype" - "github.com/gogf/gf/g/os/gtimer" - "time" + "github.com/gogf/gf/g/container/glist" + "github.com/gogf/gf/g/container/gmap" + "github.com/gogf/gf/g/container/gtype" + "github.com/gogf/gf/g/os/gtimer" + "time" ) -// LRU算法实现对象,底层双向链表使用了标准库的list.List +// LRU cache object. +// It uses list.List from stdlib for its underlying doubly linked list. type memCacheLru struct { - cache *memCache // 所属Cache对象 - data *gmap.Map // 记录键名与链表中的位置项指针 - list *glist.List // 键名历史记录链表 - rawList *glist.List // 事件列表 - closed *gtype.Bool // 是否关闭 + cache *memCache // Parent cache object. + data *gmap.Map // Key mapping to the item of the list. + list *glist.List // Key list. + rawList *glist.List // History for key adding. + closed *gtype.Bool // Closed or not. } -// 创建LRU管理对象 +// newMemCacheLru creates and returns a new LRU object. func newMemCacheLru(cache *memCache) *memCacheLru { lru := &memCacheLru { cache : cache, @@ -37,12 +37,12 @@ func newMemCacheLru(cache *memCache) *memCacheLru { return lru } -// 关闭LRU对象 +// Close closes the LRU object. func (lru *memCacheLru) Close() { lru.closed.Set(true) } -// 删除指定数据项 +// Remove deletes the FROM . func (lru *memCacheLru) Remove(key interface{}) { if v := lru.data.Get(key); v != nil { lru.data.Remove(key) @@ -50,17 +50,17 @@ func (lru *memCacheLru) Remove(key interface{}) { } } -// 当前LRU数据大小 +// Size returns the size of . func (lru *memCacheLru) Size() int { return lru.data.Size() } -// 添加LRU数据项 +// Push pushes to the tail of . func (lru *memCacheLru) Push(key interface{}) { lru.rawList.PushBack(key) } -// 从链表尾删除LRU数据项,并返回对应数据 +// Pop deletes and returns the key from tail of . func (lru *memCacheLru) Pop() interface{} { if v := lru.list.PopBack(); v != nil { lru.data.Remove(v) @@ -69,34 +69,36 @@ func (lru *memCacheLru) Pop() interface{} { return nil } -// 从链表头打印LRU链表值 -func (lru *memCacheLru) Print() { - for _, v := range lru.list.FrontAll() { - fmt.Printf("%v ", v) - } - fmt.Println() -} +// Print is used for test only. +//func (lru *memCacheLru) Print() { +// for _, v := range lru.list.FrontAll() { +// fmt.Printf("%v ", v) +// } +// fmt.Println() +//} -// 异步执行协程,将queue中的数据同步到list中 +// SyncAndClear synchronizes the keys from to and +// using Least Recently Used algorithm. func (lru *memCacheLru) SyncAndClear() { if lru.closed.Val() { gtimer.Exit() return } - // 数据同步 + // Data synchronization. for { if v := lru.rawList.PopFront(); v != nil { - // 删除对应链表项 + // Deleting the key from list. if v := lru.data.Get(v); v != nil { lru.list.Remove(v.(*glist.Element)) } - // 将数据插入到链表头,并记录对应的链表项到哈希表中,便于检索 + // Pushing key to the head of the list + // and setting its list item to hash table for quick indexing. lru.data.Set(v, lru.list.PushFront(v)) } else { break } } - // 数据清理 + // Data cleaning up. for i := lru.Size() - lru.cache.cap; i > 0; i-- { if s := lru.Pop(); s != nil { lru.cache.clearByKey(s, true) diff --git a/g/os/gcfg/gcfg.go b/g/os/gcfg/gcfg.go index 057216f16..6b8d4fedc 100644 --- a/g/os/gcfg/gcfg.go +++ b/g/os/gcfg/gcfg.go @@ -40,7 +40,7 @@ type Config struct { } // New returns a new configuration management object. -// The param specifies the default configuration file name for reading. +// The parameter specifies the default configuration file name for reading. func New(file...string) *Config { name := DEFAULT_CONFIG_FILE if len(file) > 0 { @@ -103,7 +103,7 @@ func (c *Config) filePath(file...string) (path string) { } // SetPath sets the configuration directory path for file search. -// The param can be absolute or relative path, +// The parameter can be absolute or relative path, // but absolute path is strongly recommended. func (c *Config) SetPath(path string) error { // Absolute path. diff --git a/g/os/gcfg/gcfg_instance.go b/g/os/gcfg/gcfg_instance.go index c93f22966..ee1da06f3 100644 --- a/g/os/gcfg/gcfg_instance.go +++ b/g/os/gcfg/gcfg_instance.go @@ -20,7 +20,7 @@ var ( ) // Instance returns an instance of Config with default settings. -// The param is the name for the instance. +// The parameter is the name for the instance. func Instance(name...string) *Config { key := DEFAULT_GROUP_NAME if len(name) > 0 { diff --git a/g/os/genv/genv.go b/g/os/genv/genv.go index fa377d671..6c3c391be 100644 --- a/g/os/genv/genv.go +++ b/g/os/genv/genv.go @@ -5,29 +5,33 @@ // You can obtain one at https://github.com/gogf/gf. // Package genv provides operations for environment variables of system. -// -// 环境变量管理 package genv import "os" +// All returns a copy of strings representing the environment, +// in the form "key=value". func All() []string { return os.Environ() } -// 获取环境变量,并可以指定当环境变量不存在时的默认值 -func Get(k string, def...string) string { - v, ok := os.LookupEnv(k) +// Get returns the value of the environment variable named by the . +// It returns given if the variable does not exist in the environment. +func Get(key string, def...string) string { + v, ok := os.LookupEnv(key) if !ok && len(def) > 0 { return def[0] } return v } -func Set(k, v string) error { - return os.Setenv(k, v) +// Set sets the value of the environment variable named by the . +// It returns an error, if any. +func Set(key, value string) error { + return os.Setenv(key, value) } -func Remove(k string) error { - return os.Unsetenv(k) +// Remove deletes a single environment variable. +func Remove(key string) error { + return os.Unsetenv(key) } \ No newline at end of file diff --git a/g/os/gfcache/gfcache.go b/g/os/gfcache/gfcache.go index 76e3720fe..7c96b12b6 100644 --- a/g/os/gfcache/gfcache.go +++ b/g/os/gfcache/gfcache.go @@ -5,8 +5,6 @@ // You can obtain one at https://github.com/gogf/gf. // Package gfcache provides reading and caching for file contents. -// -// 文件缓存. package gfcache import ( @@ -17,21 +15,25 @@ import ( ) const ( - // 默认的缓存超时时间(60秒) + // Default expire time for file content caching in seconds. gDEFAULT_CACHE_EXPIRE = 60 ) var ( - // 默认的缓存时间(秒) + // Default expire time for file content caching in seconds. cacheExpire = cmdenv.Get("gf.gfcache.expire", gDEFAULT_CACHE_EXPIRE).Int()*1000 ) -// 获得文件内容 string,expire参数为缓存过期时间,单位为秒。 +// GetContents returns string content of given file by from cache. +// If there's no content in the cache, it will read it from disk file specified by . +// The parameter specifies the caching time for this file content in seconds. func GetContents(path string, expire...int) string { return string(GetBinContents(path, expire...)) } -// 获得文件内容 []byte,expire参数为缓存过期时间,单位为秒。 +// GetBinContents returns []byte content of given file by from cache. +// If there's no content in the cache, it will read it from disk file specified by . +// The parameter specifies the caching time for this file content in seconds. func GetBinContents(path string, expire...int) []byte { k := cacheKey(path) e := cacheExpire @@ -41,8 +43,9 @@ func GetBinContents(path string, expire...int) []byte { r := gcache.GetOrSetFuncLock(k, func() interface{} { b := gfile.GetBinContents(path) if b != nil { - // 添加文件监控,如果文件有任何变化,立即清空缓存 - gfsnotify.Add(path, func(event *gfsnotify.Event) { + // Adding this to gfsnotify, + // it will clear its cache if there's any changes of the file. + _, _ = gfsnotify.Add(path, func(event *gfsnotify.Event) { gcache.Remove(k) gfsnotify.Exit() }) diff --git a/g/os/glog/glog_api.go b/g/os/glog/glog_api.go index d7700bfe8..5a654e2a7 100644 --- a/g/os/glog/glog_api.go +++ b/g/os/glog/glog_api.go @@ -7,13 +7,13 @@ package glog // Print prints with newline using fmt.Sprintln. -// The param can be multiple variables. +// The parameter can be multiple variables. func Print(v ...interface{}) { logger.Print(v ...) } // Printf prints with format using fmt.Sprintf. -// The param can be multiple variables. +// The parameter can be multiple variables. func Printf(format string, v ...interface{}) { logger.Printf(format, v ...) } diff --git a/g/os/glog/glog_chaining.go b/g/os/glog/glog_chaining.go index 471c96701..9e576d0ef 100644 --- a/g/os/glog/glog_chaining.go +++ b/g/os/glog/glog_chaining.go @@ -69,7 +69,7 @@ func Header(enabled...bool) *Logger { // Line is a chaining function, // which enables/disables printing its caller file along with its line number. -// The param specified whether print the long absolute file path, eg: /a/b/c/d.go:23. +// The parameter specified whether print the long absolute file path, eg: /a/b/c/d.go:23. func Line(long...bool) *Logger { return logger.Line(long...) } diff --git a/g/os/glog/glog_logger_api.go b/g/os/glog/glog_logger_api.go index 0c75f1336..7fe1c41b5 100644 --- a/g/os/glog/glog_logger_api.go +++ b/g/os/glog/glog_logger_api.go @@ -12,13 +12,13 @@ import ( ) // Print prints with newline using fmt.Sprintln. -// The param can be multiple variables. +// The parameter can be multiple variables. func (l *Logger) Print(v...interface{}) { l.printStd("", v...) } // Printf prints with format using fmt.Sprintf. -// The param can be multiple variables. +// The parameter can be multiple variables. func (l *Logger) Printf(format string, v...interface{}) { l.printStd(l.format(format, v...)) } diff --git a/g/os/glog/glog_logger_chaining.go b/g/os/glog/glog_logger_chaining.go index 1070e8882..a36842d71 100644 --- a/g/os/glog/glog_logger_chaining.go +++ b/g/os/glog/glog_logger_chaining.go @@ -157,7 +157,7 @@ func (l *Logger) Header(enabled...bool) *Logger { // Line is a chaining function, // which enables/disables printing its caller file path along with its line number. -// The param specified whether print the long absolute file path, eg: /a/b/c/d.go:23, +// The parameter specified whether print the long absolute file path, eg: /a/b/c/d.go:23, // or else short one: d.go:23. func (l *Logger) Line(long...bool) *Logger { logger := (*Logger)(nil) diff --git a/g/os/grpool/grpool.go b/g/os/grpool/grpool.go index 9add6fe8b..b7daf27f1 100644 --- a/g/os/grpool/grpool.go +++ b/g/os/grpool/grpool.go @@ -24,7 +24,7 @@ type Pool struct { var pool = New() // New creates and returns a new goroutine pool object. -// The param is used to limit the max goroutine count, +// The parameter is used to limit the max goroutine count, // which is not limited in default. func New(limit...int) *Pool { p := &Pool { diff --git a/g/os/gspath/gspath_cache.go b/g/os/gspath/gspath_cache.go index 048e283bf..deea76d2c 100644 --- a/g/os/gspath/gspath_cache.go +++ b/g/os/gspath/gspath_cache.go @@ -19,9 +19,6 @@ import ( // 递归添加目录下的文件 func (sp *SPath) updateCacheByPath(path string) { - if sp.cache == nil { - return - } sp.addToCache(path, path) } @@ -58,9 +55,6 @@ func (sp *SPath) parseCacheValue(value string) (filePath string, isDir bool) { // 添加path到缓存中(递归) func (sp *SPath) addToCache(filePath, rootPath string) { - if sp.cache == nil { - return - } // 首先添加自身 idDir := gfile.IsDir(filePath) sp.cache.SetIfNotExist(sp.nameFromPath(filePath, rootPath), sp.makeCacheValue(filePath, idDir)) @@ -83,7 +77,7 @@ func (sp *SPath) addMonitorByPath(path string) { if sp.cache == nil { return } - gfsnotify.Add(path, func(event *gfsnotify.Event) { + _, _ = gfsnotify.Add(path, func(event *gfsnotify.Event) { //glog.Debug(event.String()) switch { case event.IsRemove(): @@ -105,5 +99,5 @@ func (sp *SPath) removeMonitorByPath(path string) { if sp.cache == nil { return } - gfsnotify.Remove(path) + _ = gfsnotify.Remove(path) } \ No newline at end of file diff --git a/g/os/gview/gview.go b/g/os/gview/gview.go index 98957cef0..b484a7bf1 100644 --- a/g/os/gview/gview.go +++ b/g/os/gview/gview.go @@ -117,7 +117,7 @@ func New(path...string) *View { } // SetPath sets the template directory path for template file search. -// The param can be absolute or relative path, but absolute path is suggested. +// The parameter can be absolute or relative path, but absolute path is suggested. func (view *View) SetPath(path string) error { // Absolute path. realPath := gfile.RealPath(path) diff --git a/g/os/gview/gview_doparse.go b/g/os/gview/gview_doparse.go index ece0d3ec6..7ba9d2b2b 100644 --- a/g/os/gview/gview_doparse.go +++ b/g/os/gview/gview_doparse.go @@ -30,6 +30,7 @@ const ( var ( // Templates cache map for template folder. + // TODO Note that there's no expiring logic for this map. templates = gmap.NewStrAnyMap() ) diff --git a/g/os/gview/gview_instance.go b/g/os/gview/gview_instance.go index b4019e5dd..4d778e1a3 100644 --- a/g/os/gview/gview_instance.go +++ b/g/os/gview/gview_instance.go @@ -18,7 +18,7 @@ var ( ) // Instance returns an instance of View with default settings. -// The param is the name for the instance. +// The parameter is the name for the instance. func Instance(name ...string) *View { key := DEFAULT_INSTANCE_NAME if len(name) > 0 { diff --git a/g/test/gtest/gtest.go b/g/test/gtest/gtest.go index a2d155c58..9c3adc920 100644 --- a/g/test/gtest/gtest.go +++ b/g/test/gtest/gtest.go @@ -18,8 +18,8 @@ import ( ) // Case creates an unit test case. -// The param is the pointer to testing.T of stdlib (*testing.T). -// The param is the callback function for unit test case. +// The parameter is the pointer to testing.T of stdlib (*testing.T). +// The parameter is the callback function for unit test case. func Case(t *testing.T, f func()) { defer func() { if err := recover(); err != nil { @@ -297,7 +297,7 @@ func compareMap(value, expect interface{}) error { } // getBacktrace returns the caller backtrace content from getBacktrace. -// The param indicates the skip count of the caller backtrace from getBacktrace. +// The parameter indicates the skip count of the caller backtrace from getBacktrace. func getBacktrace(skip...int) string { customSkip := 0 if len(skip) > 0 { diff --git a/g/text/gregex/gregex_cache.go b/g/text/gregex/gregex_cache.go index f3ee27b6d..76018fe85 100644 --- a/g/text/gregex/gregex_cache.go +++ b/g/text/gregex/gregex_cache.go @@ -13,6 +13,8 @@ import ( var ( regexMu = sync.RWMutex{} + // Cache for regex object. + // TODO There's no expiring logic for this map. regexMap = make(map[string]*regexp.Regexp) ) diff --git a/geg/other/test.go b/geg/other/test.go index 9f3000841..43727a665 100644 --- a/geg/other/test.go +++ b/geg/other/test.go @@ -2,10 +2,12 @@ package main import ( "fmt" - "github.com/gogf/gf/g/os/gtime" ) func main() { - fmt.Println(gtime.Now().Format("U")) - fmt.Println(gtime.Second()) + var i float64 = 0 + for index := 0; index < 10; index++ { + i += 0.1 + fmt.Println(i) + } } \ No newline at end of file