forked from apex-enterprise-patterns/fflib-apex-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request apex-enterprise-patterns#38 from OrtooApps/feature…
…/timestamped-cache-entries Feature/timestamped cache entries
- Loading branch information
Showing
24 changed files
with
1,612 additions
and
36 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
framework/default/ortoo-core/default/classes/fflib-extension/caching/CacheEntry.cls
This file contains 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,49 @@ | ||
/** | ||
* Represents an entry that exists in the cache. | ||
* | ||
* Is dated based on the creation time so that entries can later be checked for their staleness | ||
* | ||
* @group Cache | ||
*/ | ||
public inherited sharing class CacheEntry | ||
{ | ||
Long createdOnEpoch; | ||
Object value; | ||
|
||
private Long ageInSeconds | ||
{ | ||
get | ||
{ | ||
return ortoo_DateLiterals.epochTime - this.createdOnEpoch; | ||
} | ||
} | ||
|
||
public CacheEntry( Object value ) | ||
{ | ||
this.value = value; | ||
this.createdOnEpoch = ortoo_DateLiterals.epochTime; | ||
} | ||
|
||
/** | ||
* States if the current entry is younger than or equal to the the stated age in seconds | ||
* | ||
* @param Long The age to compare against, in seconds | ||
* @return Boolean Is the current entry younger or equal to the given age | ||
*/ | ||
public Boolean isYoungerThanOrEqualTo( Long compareAgeInSeconds ) | ||
{ | ||
Contract.requires( compareAgeInSeconds != null, 'isYoungerThanOrEqualTo called with a null compareAgeInSeconds' ); | ||
|
||
return ageInSeconds <= compareAgeInSeconds; | ||
} | ||
|
||
/** | ||
* Returns the current value of the entry | ||
* | ||
* @return Object The value of the entry | ||
*/ | ||
public Object getValue() | ||
{ | ||
return this.value; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
framework/default/ortoo-core/default/classes/fflib-extension/caching/CacheEntry.cls-meta.xml
This file contains 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,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>54.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
This file contains 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 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 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 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 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.