...
To satisfy these goals, the data structure that should be cached can be defined as follows:
Code Block |
---|
|
...
| ||||
// TODO: Explore using Guava Cache
class PrivilegeCache {
private final Table<Principal, EntityId, Set<Action>> privileges = HashBasedTable.create();
public void addPrivileges(Principal principal, EntityId entityId, Set<Action> actionsToAdd) {
Set<Action> actions = privileges.get(principal, entityId);
if (actions == null) {
actions = new HashSet<>();
}
actions.addAll(actionsToAdd);
privileges.put(principal, entityId, actions);
}
public void revokePrivileges(Principal principal, EntityId entityId, Set<Action> actionsToRemove) {
Set<Action> actions = privileges.get(principal, entityId);
if (actions == null) {
throw new NoSuchElementException();
}
actions.removeAll(actionsToRemove);
privileges.put(principal, entityId, actions);
}
} |
The above cache would be re-populated asynchronously at a configurable time interval, using an AbstractScheduledService
Dependencies
Ability to distinguish between read and write operations in datasets
...