org.schemarepo
Class CacheRepository

java.lang.Object
  extended by org.schemarepo.BaseRepository
      extended by org.schemarepo.DelegatingRepository
          extended by org.schemarepo.CacheRepository
All Implemented Interfaces:
Closeable, Repository

public class CacheRepository
extends DelegatingRepository

CacheRepository is a Repository implementation that wraps another Repository and acts as a write-through cache of Subjects and schema to id mappings, shielding the inner Repository from repetitive lookups. CacheRepository can cache Subjects (which cannot be deleted) and returns an implementation of Subject that caches schema to id mappings. CacheRepository can only cache the immutable elements of a Repository, because it is intended for use in any context -- in a client, in a proxy, or above a raw implementation of a repository. It cannot cache the entire list of subjects since the list is mutable. Similarly, a cached subject cannot cache the list of schemas, the subject configuration, or the latest() schema because those are mutable.


Field Summary
 
Fields inherited from class org.schemarepo.DelegatingRepository
repo
 
Fields inherited from class org.schemarepo.BaseRepository
closed, logger
 
Constructor Summary
CacheRepository(Repository repo, RepositoryCache cache)
          Create a caching repository that wraps the provided repository using the cache provided
 
Method Summary
protected  Map<String,String> exposeConfiguration()
          Expose certain configuration elements as properties.
 Subject lookup(String subjectName)
          Returns the subject if it exists, null otherwise.
 Subject register(String subjectName, SubjectConfig config)
          Attempt to create a Subject with the given name and validator.
 Iterable<Subject> subjects()
          List all subjects.
 
Methods inherited from class org.schemarepo.DelegatingRepository
close, isValid
 
Methods inherited from class org.schemarepo.BaseRepository
toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CacheRepository

@Inject
public CacheRepository(Repository repo,
                              RepositoryCache cache)
Create a caching repository that wraps the provided repository using the cache provided

Parameters:
repo - The repository to wrap
cache - The cache to use
Method Detail

register

public Subject register(String subjectName,
                        SubjectConfig config)
Description copied from interface: Repository
Attempt to create a Subject with the given name and validator.

Specified by:
register in interface Repository
Overrides:
register in class DelegatingRepository
Parameters:
subjectName - The name of the subject. Must not be null.
config - The subject configuration. May be null.
Returns:
The newly created Subject, or an equivalent one if already created. Does not return null.

lookup

public Subject lookup(String subjectName)
Description copied from interface: Repository
Returns the subject if it exists, null otherwise.

Specified by:
lookup in interface Repository
Overrides:
lookup in class DelegatingRepository
Parameters:
subjectName - the subject name
Returns:
The subject if it exists, null otherwise.

subjects

public Iterable<Subject> subjects()
Description copied from interface: Repository
List all subjects. Does not return null.

Specified by:
subjects in interface Repository
Overrides:
subjects in class DelegatingRepository

exposeConfiguration

protected Map<String,String> exposeConfiguration()
Description copied from class: BaseRepository
Expose certain configuration elements as properties. This can be used to construct a useful toString() response, for ex.

Remember to call

super
when overriding!

Overrides:
exposeConfiguration in class DelegatingRepository
Returns:
Map representing properties; note that the actual implementation may be immutable


Copyright © 2015. All rights reserved.