# Policy Subset Loading
一些adapters支持过滤策略管理。 这意味着Casbin加载的策略是基于给定过滤器的存储策略的子集。 当解析整个策略成为性能瓶颈时,这将会允许在大型多租户环境中有效地执行策略。
To use filtered policies with a supported adapter, simply call the`LoadFilteredPolicy`method. The valid format for the filter parameter depends on the adapter used. To prevent accidental data loss, the`SavePolicy`method is disabled when a filtered policy is loaded.
例如,下面的代码片段使用内置的过滤文件adapter和带有域的RBAC模型。 在本例中,过滤器将策略限制为单个域。 Any policy lines for domains other than`"domain1"`are omitted from the loaded policy:
~~~go
import "github.com/casbin/casbin"
enforcer := casbin.NewEnforcer()
adapter := fileadapter.NewFilteredAdapter("examples/rbac_with_domains_policy.csv")
enforcer.InitWithAdapter("examples/rbac_with_domains_model.conf", adapter)
filter := &fileadapter.Filter{
P: []string{"", "domain1"},
G: []string{"", "", "domain1"},
}
enforcer.LoadFilteredPolicy(filter)
// The loaded policy now only contains the entries pertaining to "domain1".
~~~