-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ContextAdapter interface to support context in adapters (#1305
) * feat: AdapterWithContext interface * refactor: ContextAdapter interface * Update adapter_context.go * Update adapter_context.go * Update adapter_context.go --------- Co-authored-by: hsluoyz <hsluoyz@qq.com>
- Loading branch information
1 parent
3b88403
commit 37b0889
Showing
1 changed file
with
41 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2023 The casbin Authors. 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 persist | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/casbin/casbin/v2/model" | ||
) | ||
|
||
// ContextAdapter provides a context-aware interface for Casbin adapters. | ||
type ContextAdapter interface { | ||
Adapter | ||
|
||
// LoadPolicyCtx loads all policy rules from the storage with context. | ||
LoadPolicyCtx(ctx context.Context, model model.Model) error | ||
// SavePolicyCtx saves all policy rules to the storage with context. | ||
SavePolicyCtx(ctx context.Context, model model.Model) error | ||
|
||
// AddPolicyCtx adds a policy rule to the storage with context. | ||
// This is part of the Auto-Save feature. | ||
AddPolicyCtx(ctx context.Context, sec string, ptype string, rule []string) error | ||
// RemovePolicyCtx removes a policy rule from the storage with context. | ||
// This is part of the Auto-Save feature. | ||
RemovePolicyCtx(ctx context.Context, sec string, ptype string, rule []string) error | ||
// RemoveFilteredPolicyCtx removes policy rules that match the filter from the storage with context. | ||
// This is part of the Auto-Save feature. | ||
RemoveFilteredPolicyCtx(ctx context.Context, sec string, ptype string, fieldIndex int, fieldValues ...string) error | ||
} |
37b0889
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
BenchmarkCachedRaw - ns/op
24.61
ns/op24.73
ns/op1.00
BenchmarkCachedRaw - B/op
0
B/op0
B/opNaN
BenchmarkCachedRaw - allocs/op
0
allocs/op0
allocs/opNaN
BenchmarkCachedBasicModel - ns/op
285.2
ns/op300.9
ns/op0.95
BenchmarkCachedBasicModel - B/op
104
B/op104
B/op1
BenchmarkCachedBasicModel - allocs/op
4
allocs/op4
allocs/op1
BenchmarkCachedRBACModel - ns/op
280.7
ns/op294
ns/op0.95
BenchmarkCachedRBACModel - B/op
104
B/op104
B/op1
BenchmarkCachedRBACModel - allocs/op
4
allocs/op4
allocs/op1
BenchmarkCachedRBACModelSmall - ns/op
283.4
ns/op302.5
ns/op0.94
BenchmarkCachedRBACModelSmall - B/op
104
B/op104
B/op1
BenchmarkCachedRBACModelSmall - allocs/op
4
allocs/op4
allocs/op1
BenchmarkCachedRBACModelMedium - ns/op
310
ns/op317.2
ns/op0.98
BenchmarkCachedRBACModelMedium - B/op
104
B/op104
B/op1
BenchmarkCachedRBACModelMedium - allocs/op
4
allocs/op4
allocs/op1
BenchmarkCachedRBACModelLarge - ns/op
269
ns/op264.4
ns/op1.02
BenchmarkCachedRBACModelLarge - B/op
97
B/op97
B/op1
BenchmarkCachedRBACModelLarge - allocs/op
3
allocs/op3
allocs/op1
BenchmarkCachedRBACModelWithResourceRoles - ns/op
285.9
ns/op289.6
ns/op0.99
BenchmarkCachedRBACModelWithResourceRoles - B/op
104
B/op104
B/op1
BenchmarkCachedRBACModelWithResourceRoles - allocs/op
4
allocs/op4
allocs/op1
BenchmarkCachedRBACModelWithDomains - ns/op
299.1
ns/op329.9
ns/op0.91
BenchmarkCachedRBACModelWithDomains - B/op
120
B/op120
B/op1
BenchmarkCachedRBACModelWithDomains - allocs/op
4
allocs/op4
allocs/op1
BenchmarkCachedABACModel - ns/op
4422
ns/op4669
ns/op0.95
BenchmarkCachedABACModel - B/op
1520
B/op1521
B/op1.00
BenchmarkCachedABACModel - allocs/op
18
allocs/op18
allocs/op1
BenchmarkCachedKeyMatchModel - ns/op
315.6
ns/op319.7
ns/op0.99
BenchmarkCachedKeyMatchModel - B/op
152
B/op152
B/op1
BenchmarkCachedKeyMatchModel - allocs/op
4
allocs/op4
allocs/op1
BenchmarkCachedRBACModelWithDeny - ns/op
289.6
ns/op295.2
ns/op0.98
BenchmarkCachedRBACModelWithDeny - B/op
104
B/op104
B/op1
BenchmarkCachedRBACModelWithDeny - allocs/op
4
allocs/op4
allocs/op1
BenchmarkCachedPriorityModel - ns/op
283
ns/op300.6
ns/op0.94
BenchmarkCachedPriorityModel - B/op
104
B/op104
B/op1
BenchmarkCachedPriorityModel - allocs/op
4
allocs/op4
allocs/op1
BenchmarkCachedWithEnforceContext - ns/op
542.8
ns/op575
ns/op0.94
BenchmarkCachedWithEnforceContext - B/op
240
B/op240
B/op1
BenchmarkCachedWithEnforceContext - allocs/op
5
allocs/op5
allocs/op1
BenchmarkCachedRBACModelMediumParallel - ns/op
277.4
ns/op260.9
ns/op1.06
BenchmarkCachedRBACModelMediumParallel - B/op
105
B/op105
B/op1
BenchmarkCachedRBACModelMediumParallel - allocs/op
4
allocs/op4
allocs/op1
BenchmarkHasPolicySmall - ns/op
859.1
ns/op864.2
ns/op0.99
BenchmarkHasPolicySmall - B/op
150
B/op150
B/op1
BenchmarkHasPolicySmall - allocs/op
6
allocs/op6
allocs/op1
BenchmarkHasPolicyMedium - ns/op
894.2
ns/op949.1
ns/op0.94
BenchmarkHasPolicyMedium - B/op
157
B/op157
B/op1
BenchmarkHasPolicyMedium - allocs/op
6
allocs/op6
allocs/op1
BenchmarkHasPolicyLarge - ns/op
956.6
ns/op1021
ns/op0.94
BenchmarkHasPolicyLarge - B/op
165
B/op165
B/op1
BenchmarkHasPolicyLarge - allocs/op
7
allocs/op7
allocs/op1
BenchmarkAddPolicySmall - ns/op
877.3
ns/op912.3
ns/op0.96
BenchmarkAddPolicySmall - B/op
152
B/op152
B/op1
BenchmarkAddPolicySmall - allocs/op
6
allocs/op6
allocs/op1
BenchmarkAddPolicyMedium - ns/op
1130
ns/op1335
ns/op0.85
BenchmarkAddPolicyMedium - B/op
185
B/op190
B/op0.97
BenchmarkAddPolicyMedium - allocs/op
7
allocs/op7
allocs/op1
BenchmarkAddPolicyLarge - ns/op
1951
ns/op2168
ns/op0.90
BenchmarkAddPolicyLarge - B/op
417
B/op430
B/op0.97
BenchmarkAddPolicyLarge - allocs/op
9
allocs/op9
allocs/op1
BenchmarkRemovePolicySmall - ns/op
865.1
ns/op925.3
ns/op0.93
BenchmarkRemovePolicySmall - B/op
166
B/op166
B/op1
BenchmarkRemovePolicySmall - allocs/op
7
allocs/op7
allocs/op1
BenchmarkRemovePolicyMedium - ns/op
1024
ns/op1062
ns/op0.96
BenchmarkRemovePolicyMedium - B/op
179
B/op179
B/op1
BenchmarkRemovePolicyMedium - allocs/op
7
allocs/op7
allocs/op1
BenchmarkRemovePolicyLarge - ns/op
2382
ns/op2332
ns/op1.02
BenchmarkRemovePolicyLarge - B/op
305
B/op297
B/op1.03
BenchmarkRemovePolicyLarge - allocs/op
13
allocs/op13
allocs/op1
BenchmarkRaw - ns/op
24.3
ns/op24.83
ns/op0.98
BenchmarkRaw - B/op
0
B/op0
B/opNaN
BenchmarkRaw - allocs/op
0
allocs/op0
allocs/opNaN
BenchmarkBasicModel - ns/op
5703
ns/op6203
ns/op0.92
BenchmarkBasicModel - B/op
1491
B/op1489
B/op1.00
BenchmarkBasicModel - allocs/op
17
allocs/op17
allocs/op1
BenchmarkRBACModel - ns/op
8300
ns/op9743
ns/op0.85
BenchmarkRBACModel - B/op
2038
B/op2032
B/op1.00
BenchmarkRBACModel - allocs/op
35
allocs/op35
allocs/op1
BenchmarkRBACModelSizes/small - ns/op
78977
ns/op85933
ns/op0.92
BenchmarkRBACModelSizes/small - B/op
20016
B/op20001
B/op1.00
BenchmarkRBACModelSizes/small - allocs/op
480
allocs/op480
allocs/op1
BenchmarkRBACModelSizes/medium - ns/op
958915
ns/op1034963
ns/op0.93
BenchmarkRBACModelSizes/medium - B/op
191303
B/op191262
B/op1.00
BenchmarkRBACModelSizes/medium - allocs/op
4826
allocs/op4827
allocs/op1.00
BenchmarkRBACModelSizes/large - ns/op
10072846
ns/op12002893
ns/op0.84
BenchmarkRBACModelSizes/large - B/op
1894800
B/op1913428
B/op0.99
BenchmarkRBACModelSizes/large - allocs/op
48040
allocs/op48547
allocs/op0.99
BenchmarkRBACModelSmall - ns/op
90194
ns/op102949
ns/op0.88
BenchmarkRBACModelSmall - B/op
20105
B/op20044
B/op1.00
BenchmarkRBACModelSmall - allocs/op
615
allocs/op615
allocs/op1
BenchmarkRBACModelMedium - ns/op
925728
ns/op1028840
ns/op0.90
BenchmarkRBACModelMedium - B/op
194240
B/op194148
B/op1.00
BenchmarkRBACModelMedium - allocs/op
6024
allocs/op6024
allocs/op1
BenchmarkRBACModelLarge - ns/op
10995712
ns/op13069146
ns/op0.84
BenchmarkRBACModelLarge - B/op
1952396
B/op1954091
B/op1.00
BenchmarkRBACModelLarge - allocs/op
61097
allocs/op61164
allocs/op1.00
BenchmarkRBACModelWithResourceRoles - ns/op
6879
ns/op7598
ns/op0.91
BenchmarkRBACModelWithResourceRoles - B/op
1823
B/op1820
B/op1.00
BenchmarkRBACModelWithResourceRoles - allocs/op
27
allocs/op27
allocs/op1
BenchmarkRBACModelWithDomains - ns/op
7779
ns/op8634
ns/op0.90
BenchmarkRBACModelWithDomains - B/op
1806
B/op1803
B/op1.00
BenchmarkRBACModelWithDomains - allocs/op
25
allocs/op25
allocs/op1
BenchmarkABACModel - ns/op
4274
ns/op4809
ns/op0.89
BenchmarkABACModel - B/op
1515
B/op1512
B/op1.00
BenchmarkABACModel - allocs/op
17
allocs/op17
allocs/op1
BenchmarkABACRuleModel - ns/op
5683517
ns/op6256070
ns/op0.91
BenchmarkABACRuleModel - B/op
1305638
B/op1304174
B/op1.00
BenchmarkABACRuleModel - allocs/op
40088
allocs/op40088
allocs/op1
BenchmarkKeyMatchModel - ns/op
9026
ns/op10028
ns/op0.90
BenchmarkKeyMatchModel - B/op
3027
B/op3020
B/op1.00
BenchmarkKeyMatchModel - allocs/op
37
allocs/op37
allocs/op1
BenchmarkRBACModelWithDeny - ns/op
10934
ns/op11700
ns/op0.93
BenchmarkRBACModelWithDeny - B/op
2448
B/op2445
B/op1.00
BenchmarkRBACModelWithDeny - allocs/op
49
allocs/op49
allocs/op1
BenchmarkPriorityModel - ns/op
6280
ns/op7363
ns/op0.85
BenchmarkPriorityModel - B/op
1741
B/op1738
B/op1.00
BenchmarkPriorityModel - allocs/op
22
allocs/op22
allocs/op1
BenchmarkRBACModelWithDomainPatternLarge - ns/op
34289
ns/op41277
ns/op0.83
BenchmarkRBACModelWithDomainPatternLarge - B/op
16602
B/op16611
B/op1.00
BenchmarkRBACModelWithDomainPatternLarge - allocs/op
164
allocs/op164
allocs/op1
BenchmarkRoleManagerSmall - ns/op
121817
ns/op125101
ns/op0.97
BenchmarkRoleManagerSmall - B/op
11953
B/op11952
B/op1.00
BenchmarkRoleManagerSmall - allocs/op
797
allocs/op797
allocs/op1
BenchmarkRoleManagerMedium - ns/op
1257872
ns/op1310573
ns/op0.96
BenchmarkRoleManagerMedium - B/op
125908
B/op125907
B/op1.00
BenchmarkRoleManagerMedium - allocs/op
8741
allocs/op8741
allocs/op1
BenchmarkRoleManagerLarge - ns/op
15997523
ns/op18311677
ns/op0.87
BenchmarkRoleManagerLarge - B/op
1349920
B/op1349920
B/op1
BenchmarkRoleManagerLarge - allocs/op
89741
allocs/op89741
allocs/op1
BenchmarkBuildRoleLinksWithPatternLarge - ns/op
9639008475
ns/op11254167453
ns/op0.86
BenchmarkBuildRoleLinksWithPatternLarge - B/op
5294561368
B/op5289092176
B/op1.00
BenchmarkBuildRoleLinksWithPatternLarge - allocs/op
60938206
allocs/op60936349
allocs/op1.00
BenchmarkBuildRoleLinksWithDomainPatternLarge - ns/op
257551844
ns/op326736696
ns/op0.79
BenchmarkBuildRoleLinksWithDomainPatternLarge - B/op
140019348
B/op139839698
B/op1.00
BenchmarkBuildRoleLinksWithDomainPatternLarge - allocs/op
1676221
allocs/op1676165
allocs/op1.00
BenchmarkBuildRoleLinksWithPatternAndDomainPatternLarge - ns/op
9926721989
ns/op11517714364
ns/op0.86
BenchmarkBuildRoleLinksWithPatternAndDomainPatternLarge - B/op
5432188224
B/op5425607368
B/op1.00
BenchmarkBuildRoleLinksWithPatternAndDomainPatternLarge - allocs/op
62548730
allocs/op62546688
allocs/op1.00
BenchmarkHasLinkWithPatternLarge - ns/op
16006
ns/op17972
ns/op0.89
BenchmarkHasLinkWithPatternLarge - B/op
7551
B/op7547
B/op1.00
BenchmarkHasLinkWithPatternLarge - allocs/op
111
allocs/op111
allocs/op1
BenchmarkHasLinkWithDomainPatternLarge - ns/op
852.1
ns/op909.1
ns/op0.94
BenchmarkHasLinkWithDomainPatternLarge - B/op
80
B/op80
B/op1
BenchmarkHasLinkWithDomainPatternLarge - allocs/op
5
allocs/op5
allocs/op1
BenchmarkHasLinkWithPatternAndDomainPatternLarge - ns/op
16425
ns/op17606
ns/op0.93
BenchmarkHasLinkWithPatternAndDomainPatternLarge - B/op
7550
B/op7549
B/op1.00
BenchmarkHasLinkWithPatternAndDomainPatternLarge - allocs/op
111
allocs/op111
allocs/op1
This comment was automatically generated by workflow using github-action-benchmark.