정책 하위 집합 로드
일부 adapters는 **필터링된 정책 로드(filtered policy loading)**를 지원합니다. 즉, 필터에 따라 스토리지에서 정책의 하위 집합만 로드됩니다. 전체 정책 세트를 로드하기 비현실적인 대용량 또는 멀티 테넌트 설정에서 메모리 사용량을 줄이고 속도를 향상시 킵니다.
지원되는 어댑터로 LoadFilteredPolicy(filter)를 호출하세요. 필터 형식은 어댑터마다 다릅니다. 필터링된 로드를 사용할 때, 실수로 전체 정책을 덮어쓰지 않도록 SavePolicy()가 비활성화됩니다.
예시: 도메인이 있는 RBAC 모델과 함께 필터링된 파일 어댑터를 사용하는 경우입니다. 이 필터는 domain1에 대한 정책만 로드합니다:
import (
"github.com/casbin/casbin/v3"
fileadapter "github.com/casbin/casbin/v3/persist/file-adapter"
)
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)
// Only policies for "domain1" are loaded.
LoadIncrementalFilteredPolicy(filter)는 LoadFilteredPolicy와 유사하게 작동하지만, 현재 메모리에 있는 정책을 대체하는 대신 필터링된 정책을 추가합니다. 여러 개의 필터링된 로드(예: 테넌트별)를 하나의 인포서에 결합할 수 있습니다.
Comments are powered by giscus and GitHub Discussions. They load from giscus.app and GitHub only after you click the button below.