Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Spring insight results for retrieve client without caching

Spring insight results for retrieve clientImage RemovedSpring insight results for retrieve clientImage Added

Cache eviction

...

Code Block
languagejava
    /*
     * Although this method is eligible for caching we cannot add caching for this method
     * ,as the return value also depends on the logged in user.
     * */    
    // @Cacheable(value = "clients", key =
    // "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getName().concat(#clientId)")
    public ClientData retrieveOne(final Long clientId) {
        try {
            AppUser currentUser = context.authenticatedUser();
            String hierarchy = currentUser.getOffice().getHierarchy();
            String hierarchySearchString = hierarchy + "%";
            String sql = "select " + this.clientMapper.schema() + " where o.hierarchy like ? and c.id = ?";
            ClientData clientData = this.jdbcTemplate.queryForObject(sql, this.clientMapper,
                    new Object[] { hierarchySearchString, clientId });
            String clientGroupsSql = "select " + this.clientGroupsMapper.parentGroupsSchema();
            Collection<GroupGeneralData> parentGroups = this.jdbcTemplate.query(clientGroupsSql, this.clientGroupsMapper,
                    new Object[] { clientId });
            return ClientData.setParentGroups(clientData, parentGroups);
        } catch (EmptyResultDataAccessException e) {
            throw new ClientNotFoundException(clientId);
        }
    }

Plugging in different cache managers

So far I've been using the default cachemanager provided by spring cache module. It is most suitable for small non distributed environments. When the systems grows JDK inmemory hash map will not be sufficient to server the demand. There are couple of alternatives available off the shelf for example Ehcahce, Memcached, Spring Gemfire. I've tried both ehcache and memcached they all works pretty well with spring cache abstraction thus there are couple of challenges remain with integration. More details about these framework integration can be found here.

Links to Stack Overflow posts.

...