protected boolean addFunctionFromCachedRepository(
     final InMemoryCompiledFunctionRepository before,
     final InMemoryCompiledFunctionRepository after,
     final InMemoryCompiledFunctionRepository compiled,
     final FunctionDefinition function,
     final Instant atInstant) {
   if (before != null) {
     final CompiledFunctionDefinition compiledFunction =
         before.findDefinition(function.getUniqueId());
     if (compiledFunction.getLatestInvocationTime() == null) {
       // previous one always valid
       compiled.addFunction(compiledFunction);
       return true;
     } else {
       final Instant validUntil = Instant.of(compiledFunction.getLatestInvocationTime());
       if (!validUntil.isBefore(atInstant)) {
         // previous one still valid
         compiled.addFunction(compiledFunction);
         return true;
       }
     }
   }
   if (after != null) {
     final CompiledFunctionDefinition compiledFunction =
         after.findDefinition(function.getUniqueId());
     if (compiledFunction.getEarliestInvocationTime() == null) {
       // next one always valid
       compiled.addFunction(compiledFunction);
       return true;
     } else {
       final Instant validFrom = Instant.of(compiledFunction.getEarliestInvocationTime());
       if (!validFrom.isAfter(atInstant)) {
         // next one already valid
         compiled.addFunction(compiledFunction);
         return true;
       }
     }
   }
   return false;
 }
    @Override
    public CompiledFunctionDefinition compile(
        FunctionCompilationContext context, InstantProvider atInstantProvider) {
      _compileCount.incrementAndGet();
      final Instant atInstant = Instant.of(atInstantProvider);
      final AbstractFunction.AbstractCompiledFunction compiled =
          new AbstractFunction.AbstractCompiledFunction() {

            @Override
            public ComputationTargetType getTargetType() {
              return null;
            }

            @Override
            public Set<ValueSpecification> getResults(
                FunctionCompilationContext context, ComputationTarget target) {
              return null;
            }

            @Override
            public Set<ValueRequirement> getRequirements(
                FunctionCompilationContext context,
                ComputationTarget target,
                final ValueRequirement desiredValue) {
              return null;
            }

            @Override
            public FunctionInvoker getFunctionInvoker() {
              return null;
            }

            @Override
            public boolean canApplyTo(
                FunctionCompilationContext context, ComputationTarget target) {
              return false;
            }
          };
      if (_validBefore != null) {
        compiled.setEarliestInvocationTime(atInstant.minusMillis(_validBefore));
      }
      if (_validAfter != null) {
        compiled.setLatestInvocationTime(atInstant.plusMillis(_validAfter));
      }
      return compiled;
    }
 @Override
 public CompiledFunctionRepository compile(
     final FunctionRepository repository,
     final FunctionCompilationContext context,
     final ExecutorService executor,
     final InstantProvider atInstantProvider) {
   clearInvalidCache(context.getFunctionInitId());
   final Instant atInstant = Instant.of(atInstantProvider);
   final Pair<FunctionRepository, Instant> key = Pair.of(repository, atInstant);
   // Try a previous compilation
   final InMemoryCompiledFunctionRepository previous = getPreviousCompilation(key);
   if (previous != null) {
     if (previous.getLatestInvocationTime() == null) {
       return previous;
     } else {
       if (!atInstant.isAfter(previous.getLatestInvocationTime())) {
         return previous;
       }
     }
   }
   // Try a future compilation
   final InMemoryCompiledFunctionRepository next = getNextCompilation(key);
   if (next != null) {
     if (next.getEarliestInvocationTime() == null) {
       return next;
     } else {
       if (!atInstant.isBefore(next.getEarliestInvocationTime())) {
         return next;
       }
     }
   }
   // Try the exact timestamp
   InMemoryCompiledFunctionRepository compiled = getCachedCompilation(key);
   if (compiled != null) {
     return compiled;
   }
   // Create a compilation, salvaging results from previous and next if possible
   compiled = compile(context, repository, atInstant, previous, next, executor);
   cacheCompilation(key, compiled);
   return compiled;
 }