-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Policy cache invalidation approach #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a655827
feat: Experimenting with cache invalidation
rodmgwgu e35079e
squash!: Cleanup
rodmgwgu fc90291
squash!: Re-enable autoload setting, but default to disabled
rodmgwgu bccdd3d
squash!: Cleanup
rodmgwgu 132b339
squash!: Add tests
rodmgwgu a45426e
squash!: Update Changelog and version
rodmgwgu a4292b5
squash!: Format code, bump version
rodmgwgu 67fbbdb
squash!: Changed approach to use DB instead of cache
rodmgwgu 8da767b
squash!: Add tests for PolicyCacheControl model
rodmgwgu 5f03619
squash!: Changed implementation to use UUID for cache invalidation
rodmgwgu b7f31cc
squash!: Attend PR comments
rodmgwgu de47a7d
squash!: Fix migrations conflict
rodmgwgu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Generated by Django 4.2.24 on 2025-11-14 22:38 | ||
|
|
||
| import uuid | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("openedx_authz", "0004_contentlibraryscope"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="PolicyCacheControl", | ||
| fields=[ | ||
| ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
| ("version", models.UUIDField(default=uuid.uuid4)), | ||
| ], | ||
| ), | ||
| ] |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| """Models for the authorization engine.""" | ||
|
|
||
| from uuid import UUID, uuid4 | ||
|
|
||
| from django.db import models | ||
|
|
||
|
|
||
| class PolicyCacheControl(models.Model): | ||
| """Model to control policy cache invalidation. | ||
|
|
||
| This model can be used to trigger cache invalidation for authorization policies | ||
| by changing the version. Whenever this model is updated, the authorization | ||
| engine should invalidate its cached policies. | ||
|
|
||
| .. no_pii: | ||
| """ | ||
|
|
||
| version = models.UUIDField(default=uuid4) | ||
|
|
||
| def save(self, *args, **kwargs): | ||
| """Override save to ensure a single instance.""" | ||
| self.pk = 1 # Ensure a single instance | ||
| super().save(*args, **kwargs) | ||
|
|
||
| @classmethod | ||
| def get(cls): | ||
| """Get the singleton instance of the model.""" | ||
| obj, _ = cls.objects.get_or_create(pk=1) | ||
| return obj | ||
|
|
||
| @classmethod | ||
| def get_version(cls): | ||
| """Get the version for policy cache control. | ||
|
|
||
| Returns: | ||
| UUID: The version of the last update. | ||
| """ | ||
| instance = cls.get() | ||
| return instance.version | ||
|
|
||
| @classmethod | ||
| def set_version(cls, version: UUID): | ||
| """Update the cache version. | ||
|
|
||
| This method updates the cache version, which can be used to signal | ||
| that the policy cache should be invalidated. | ||
| """ | ||
| instance = cls.get() | ||
| instance.version = version | ||
|
|
||
| instance.save() |
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.