class CloudDatastoreCache extends AbstractRemoteCache {

    @Override
    public byte[] get(String key) {
        Datastore datastore = getService();
        KeyFactory keyFactory = datastore.newKeyFactory().setKind(CACHE_KIND);
        Key datastoreKey = keyFactory.newKey(key);
        Entity entity = datastore.get(datastoreKey);
        if (entity != null) {
            long expiry = entity.getLong(CACHE_EXPIRY_FIELD);
            long now = TimeUtils.currentTimeMillis();
            if (expiry == 0 || now < expiry) {
                return entity.getBlob(CACHE_VALUE_FIELD).toByteArray();
            }
        }
        return null;
    }

}