<commit_before>package app;

import com.darwino.commons.json.JsonException;
import com.darwino.jsonstore.Attachment;
import com.darwino.jsonstore.Database;
import com.darwino.jsonstore.Document;
import com.darwino.jsonstore.Store;
import frostillicus.blog.app.AppDatabaseDef;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;

@Path(MediaResource.PATH)
public class MediaResource {
    public static final String PATH = "media";

    @Inject
    Database database;

    @GET
    @Path("{mediaId}/{mediaName}")
    public Response get(@PathParam("mediaId") String mediaId) throws JsonException {
        Store store = database.getStore(AppDatabaseDef.STORE_MEDIA);
        Document doc = store.loadDocument(mediaId);

        Attachment att = doc.getAttachments()[0];

        return Response.ok(att.getInputStream()).header(HttpHeaders.CONTENT_TYPE, att.getMimeType()).build();
    }
}<commit_msg>Implement caching in MediaResource<commit_after>package app;

import com.darwino.commons.json.JsonException;
import com.darwino.jsonstore.Attachment;
import com.darwino.jsonstore.Database;
import com.darwino.jsonstore.Document;
import com.darwino.jsonstore.Store;
import frostillicus.blog.app.AppDatabaseDef;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.*;

@Path(MediaResource.PATH)
public class MediaResource {
    public static final String PATH = "media";

    @Inject
    Database database;

    @Context
    Request request;

    @GET
    @Path("{mediaId}/{mediaName}")
    public Response get(@PathParam("mediaId") String mediaId) throws JsonException {
        Store store = database.getStore(AppDatabaseDef.STORE_MEDIA);
        Document doc = store.loadDocument(mediaId);

        Attachment att = doc.getAttachments()[0];

        EntityTag etag = new EntityTag(att.getETag());
        Response.ResponseBuilder builder = request.evaluatePreconditions(etag);
        if(builder == null) {
            builder = Response.ok(att.getInputStream())
                    .header(HttpHeaders.CONTENT_TYPE, att.getMimeType())
                    .header(HttpHeaders.ETAG, etag);
        }

        CacheControl cc = new CacheControl();
        cc.setMaxAge(5 * 24 * 60 * 60);

        return builder
                .cacheControl(cc)
                .build();
    }
}
{'fraction_non_alphanumeric': 0.11361804995970991, 'fraction_numerical': 0.0036261079774375505, 'mean_word_length': 3.4900542495479203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6891995', 'n_tokens_mistral': 762, 'n_tokens_neox': 741, 'n_words': 148}