feat(adapter): add lazyLoad parameter to initWithAdapter in newEnforcerWithClass#503
Merged
hsluoyz merged 1 commit intoapache:masterfrom Sep 22, 2025
Merged
Conversation
github-actions bot
pushed a commit
that referenced
this pull request
Sep 22, 2025
# [5.39.0](v5.38.0...v5.39.0) (2025-09-22) ### Features * **adapter:** add lazyLoad parameter to initWithAdapter in newEnforcerWithClass ([#503](#503)) ([b9a3d45](b9a3d45))
|
🎉 This PR is included in version 5.39.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
newEnforcerfunction is a key entry point for initializing an Enforcer instance in theCasbinlibrary. This change introduces the ability to control lazy loading during the initialization process. Lazy loading allows users to defer the loading of policies until explicitly required, which can improve performance in scenarios where policy loading is not immediately necessary.By adding a
lazyLoadparameter to thenewEnforcerinitialization process, users gain more flexibility in managing their application's performance and resource usage. This is particularly useful in environments where policy data is large or where initialization speed is critical.Before the Change
Previously, the newEnforcer function would always load policies during initialization, regardless of whether they were needed immediately. For example:
This behavior could lead to unnecessary overhead in cases where the policies were not used right away.
After the Change
With the lazyLoad parameter, users can now control when policies are loaded:
This approach provides the following benefits:
Improved Performance: Policies are loaded only when needed, reducing initialization time.
Resource Optimization: Avoids loading large policy files unnecessarily.
Flexibility: Users can decide the best time to load policies based on their application's workflow.
Scenario: Frequent Dynamic Policy Creation with Large Policy Sets
In some applications, policies are not static but are dynamically created and updated frequently. For example, consider a multi-tenant system where each tenant has millions of policies that are stored in a database. Loading all these policies into memory at once can lead to significant performance bottlenecks, especially when the policies are not immediately required.
With the introduction of the lazyLoad parameter, users can now defer the loading of these large policy sets until they are explicitly needed. This is particularly useful in scenarios where:
Dynamic Policy Creation: Policies are being created or updated frequently, and loading them into memory every time would be inefficient.
Large Policy Sets: The number of policies is in the millions, making in-memory storage impractical due to memory constraints.
Selective Policy Usage: Only a subset of policies is required at any given time, and loading all policies upfront would waste resources.