class OperationServiceImpl implements OperationService {

    public List<DbOperationRecordDto> getOperations(Long lastId, Integer limit) {
        Long mostRecentId = getMostRecentId();

        if (mostRecentId == null) {
            return null;
        }

        long beginId = lastId + 1;
        // TODO if there is a big difference between beginId and the most recent id, binary search for the true start
        long endId = limit != null ? Math.min(lastId + limit, mostRecentId) : mostRecentId;

        if (beginId > endId) {
            return null;
        }

        Map<String, Object> recordsByKey = memcacheService.getAll(getNewOperationRecordKeys(beginId, endId));
        // TODO trimming missing results only from the end of the range is incorrect, as there are scenarios
        // in which there could be missing records in the middle. We need a better approach to this that
        // always retrieves all missing records.

        List<DbOperationRecordDto> records = new ArrayList<DbOperationRecordDto>(recordsByKey.size());
        for (Object recordObject : recordsByKey.values()) {
            records.add((DbOperationRecordDto) recordObject);
        }

        return records;
    }

    @Inject  OperationServiceImpl(
            MemcacheService memcacheService);

}