Skip to content

Commit

Permalink
Move the ModelCacheTag usage to the ModelCache interface
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Nov 27, 2020
1 parent c6284ce commit 7777c6f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1422,15 +1422,15 @@ private <T> void intoCache( ModelCache modelCache, String groupId, String artifa
{
if ( modelCache != null )
{
modelCache.put( groupId, artifactId, version, tag.getName(), tag.intoCache( data ) );
modelCache.put( groupId, artifactId, version, tag, data );
}
}

private <T> void intoCache( ModelCache modelCache, Source source, ModelCacheTag<T> tag, T data )
{
if ( modelCache != null )
{
modelCache.put( source, tag.getName(), tag.intoCache( data ) );
modelCache.put( source, tag, data );
}
}

Expand All @@ -1439,11 +1439,7 @@ private <T> T fromCache( ModelCache modelCache, String groupId, String artifactI
{
if ( modelCache != null )
{
Object data = modelCache.get( groupId, artifactId, version, tag.getName() );
if ( data != null )
{
return tag.fromCache( tag.getType().cast( data ) );
}
return modelCache.get( groupId, artifactId, version, tag );
}
return null;
}
Expand All @@ -1452,11 +1448,7 @@ private <T> T fromCache( ModelCache modelCache, Source source, ModelCacheTag<T>
{
if ( modelCache != null )
{
Object data = modelCache.get( source, tag.getName() );
if ( data != null )
{
return tag.fromCache( tag.getType().cast( data ) );
}
return modelCache.get( source, tag );
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,60 @@ default Object get( Source path, String tag )
*/
Object get( String groupId, String artifactId, String version, String tag );

/**
* Puts the specified data into the cache.
*
* @param path The path of the cache record, must not be {@code null}.
* @param tag The tag of the cache record, must not be {@code null}.
* @param data The data to store in the cache, must not be {@code null}.
* @since 3.7.0
*/
default <T> void put( Source path, ModelCacheTag<T> tag, T data )
{
put( path, tag.getName(), tag.intoCache( data ) );
}

/**
* Gets the specified data from the cache.
*
* @param path The path of the cache record, must not be {@code null}.
* @param tag The tag of the cache record, must not be {@code null}.
* @return The requested data or {@code null} if none was present in the cache.
* @since 3.7.0
*/
default <T> T get( Source path, ModelCacheTag<T> tag )
{
Object obj = get( path, tag.getName() );
return ( obj != null ) ? tag.fromCache( tag.getType().cast( obj ) ) : null;
}

/**
* Puts the specified data into the cache.
*
* @param groupId The group id of the cache record, must not be {@code null}.
* @param artifactId The artifact id of the cache record, must not be {@code null}.
* @param version The version of the cache record, must not be {@code null}.
* @param tag The tag of the cache record, must not be {@code null}.
* @param data The data to store in the cache, must not be {@code null}.
*/
default <T> void put( String groupId, String artifactId, String version, ModelCacheTag<T> tag, T data )
{
put( groupId, artifactId, version, tag.getName(), tag.intoCache( data ) );
}

/**
* Gets the specified data from the cache.
*
* @param groupId The group id of the cache record, must not be {@code null}.
* @param artifactId The artifact id of the cache record, must not be {@code null}.
* @param version The version of the cache record, must not be {@code null}.
* @param tag The tag of the cache record, must not be {@code null}.
* @return The requested data or {@code null} if none was present in the cache.
*/
default <T> T get( String groupId, String artifactId, String version, ModelCacheTag<T> tag )
{
Object obj = get( groupId, artifactId, version, tag.getName() );
return ( obj != null ) ? tag.fromCache( tag.getType().cast( obj ) ) : null;
}

}

0 comments on commit 7777c6f

Please sign in to comment.