# 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".
~~~