Skip to content

Commit

Permalink
fix: Adjust preheat caches for new tracker importer (#7606)
Browse files Browse the repository at this point in the history
* Add specific cache capacity for all preheat caches. lower the default cache capacity

* fix: typo

* fix: Fixed failing tests
  • Loading branch information
stian-sandvold authored Mar 11, 2021
1 parent 356e424 commit 4b36ab6
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @author Luciano Fiandesio
*/
@Component
@StrategyFor( value = CategoryOptionCombo.class, mapper = CategoryOptionComboMapper.class, cache = true, ttl = 30 )
@StrategyFor( value = CategoryOptionCombo.class, mapper = CategoryOptionComboMapper.class, cache = true, ttl = 5 )
public class CatOptionComboStrategy extends AbstractSchemaStrategy
{
public CatOptionComboStrategy( SchemaService schemaService, QueryService queryService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @author Luciano Fiandesio
*/
@Component
@StrategyFor( value = CategoryOption.class, mapper = CategoryOptionMapper.class, cache = true, ttl = 30 )
@StrategyFor( value = CategoryOption.class, mapper = CategoryOptionMapper.class, cache = true, ttl = 30, capacity = 5 )
public class CatOptionStrategy extends AbstractSchemaStrategy
{
public CatOptionStrategy( SchemaService schemaService, QueryService queryService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @author Luciano Fiandesio
*/
@Component
@StrategyFor( value = OrganisationUnit.class, mapper = OrganisationUnitMapper.class, cache = true, ttl = 30, capacity = 2000 )
@StrategyFor( value = OrganisationUnit.class, mapper = OrganisationUnitMapper.class, cache = true, ttl = 30, capacity = 100 )
public class OrgUnitStrategy extends AbstractSchemaStrategy
{
public OrgUnitStrategy( SchemaService schemaService, QueryService queryService, IdentifiableObjectManager manager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @author Luciano Fiandesio
*/
@Component
@StrategyFor( value = ProgramStage.class, mapper = ProgramStageMapper.class, cache = true, ttl = 20 )
@StrategyFor( value = ProgramStage.class, mapper = ProgramStageMapper.class, cache = true, ttl = 20, capacity = 30 )
public class ProgramStageStrategy extends AbstractSchemaStrategy
{
public ProgramStageStrategy( SchemaService schemaService, QueryService queryService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @author Luciano Fiandesio
*/
@Component
@StrategyFor( value = Program.class, mapper = ProgramMapper.class, cache = true, ttl = 20 )
@StrategyFor( value = Program.class, mapper = ProgramMapper.class, cache = true, ttl = 20, capacity = 10 )
public class ProgramStrategy extends AbstractSchemaStrategy
{
public ProgramStrategy( SchemaService schemaService, QueryService queryService, IdentifiableObjectManager manager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @author Luciano Fiandesio
*/
@Component
@StrategyFor( value = RelationshipType.class, mapper = RelationshipTypeMapper.class, cache = true, ttl = 10 )
@StrategyFor( value = RelationshipType.class, mapper = RelationshipTypeMapper.class, cache = true, ttl = 10, capacity = 10 )
public class RelationshipTypeStrategy extends AbstractSchemaStrategy
{
public RelationshipTypeStrategy( SchemaService schemaService, QueryService queryService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@
int ttl() default 5;

/**
* The maximum number of entries hold by the cache. Defaults to
* Long.MAX_VALUE
* The maximum number of entries hold by the cache. Defaults to 5. The
* reason for the low default, is that certain objects can contain a lot of
* references and quickly consume memory. For most metadata, a capacity of 5
* is not necessarily small either. We should always specify capacity for
* each strategy, on not rely on the default.
*/
long capacity() default Long.MAX_VALUE;
long capacity() default 5;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @author Luciano Fiandesio
*/
@Component
@StrategyFor( value = TrackedEntityType.class, mapper = TrackedEntityTypeMapper.class, cache = true, ttl = 10 )
@StrategyFor( value = TrackedEntityType.class, mapper = TrackedEntityTypeMapper.class, cache = true, ttl = 10, capacity = 5 )
public class TrackedEntityTypeStrategy extends AbstractSchemaStrategy
{
public TrackedEntityTypeStrategy( SchemaService schemaService, QueryService queryService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void verifyFetchWildcardObjectsFromDbAndPutInCache()

verify( cache, times( 1 ) ).hasKey( "RelationshipType" );

verify( cache, times( 5 ) ).put( eq( "RelationshipType" ), anyString(), any(), eq( 10 ), eq( Long.MAX_VALUE ) );
verify( cache, times( 5 ) ).put( eq( "RelationshipType" ), anyString(), any(), eq( 10 ), eq( 10L ) );
}

@Test
Expand Down Expand Up @@ -162,7 +162,7 @@ public void verifyObjectNotInCacheIsFetchedFromDbAndPutInCache()
// Then
assertThat( preheat.getAll( Program.class ), hasSize( 1 ) );

verify( cache, times( 1 ) ).put( eq( "Program" ), anyString(), any(), eq( 20 ), eq( Long.MAX_VALUE ) );
verify( cache, times( 1 ) ).put( eq( "Program" ), anyString(), any(), eq( 20 ), eq( 10L ) );
}

}

0 comments on commit 4b36ab6

Please sign in to comment.