-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from FishGoddess/develop
v0.6.0-alpha
- Loading branch information
Showing
34 changed files
with
322 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2024 FishGoddess. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cachego | ||
|
||
const ( | ||
// standard cache is a simple cache with locked map. | ||
// It evicts entries randomly if cache size reaches to max entries. | ||
standard CacheType = "standard" | ||
|
||
// lru cache is a cache using lru to evict entries. | ||
// More details see https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU). | ||
lru CacheType = "lru" | ||
|
||
// lfu cache is a cache using lfu to evict entries. | ||
// More details see https://en.wikipedia.org/wiki/Cache_replacement_policies#Least-frequently_used_(LFU). | ||
lfu CacheType = "lfu" | ||
) | ||
|
||
// CacheType is the type of cache. | ||
type CacheType string | ||
|
||
// String returns the cache type in string form. | ||
func (ct CacheType) String() string { | ||
return string(ct) | ||
} | ||
|
||
// IsStandard returns if cache type is standard. | ||
func (ct CacheType) IsStandard() bool { | ||
return ct == standard | ||
} | ||
|
||
// IsLRU returns if cache type is lru. | ||
func (ct CacheType) IsLRU() bool { | ||
return ct == lru | ||
} | ||
|
||
// IsLFU returns if cache type is lfu. | ||
func (ct CacheType) IsLFU() bool { | ||
return ct == lfu | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2024 FishGoddess. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cachego | ||
|
||
import "testing" | ||
|
||
// go test -v -cover -count=1 -test.cpu=1 -run=^TestCacheType$ | ||
func TestCacheType(t *testing.T) { | ||
if standard.String() != string(standard) { | ||
t.Fatalf("standard.String() %s is wrong", standard.String()) | ||
} | ||
|
||
if lru.String() != string(lru) { | ||
t.Fatalf("lru.String() %s is wrong", lru.String()) | ||
} | ||
|
||
if lfu.String() != string(lfu) { | ||
t.Fatalf("lfu.String() %s is wrong", lfu.String()) | ||
} | ||
|
||
if !standard.IsStandard() { | ||
t.Fatal("!standard.IsStandard()") | ||
} | ||
|
||
if !lru.IsLRU() { | ||
t.Fatal("!standard.IsLRU()") | ||
} | ||
|
||
if !lfu.IsLFU() { | ||
t.Fatal("!standard.IsLFU()") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.