Example #1
0
  /*
   * @see org.alfresco.repo.content.ContentStore#getWriter(org.alfresco.repo.content.ContentContext)
   */
  @Override
  public ContentWriter getWriter(final ContentContext context) {
    if (cacheOnInbound) {
      final ContentWriter bsWriter = backingStore.getWriter(context);

      // write to cache
      final ContentWriter cacheWriter = cache.getWriter(bsWriter.getContentUrl());

      cacheWriter.addListener(
          new ContentStreamListener() {
            @Override
            public void contentStreamClosed() throws ContentIOException {
              // Finished writing to the cache, so copy to the backing store -
              // ensuring that the encoding attributes are set to the same as for the cache writer.
              bsWriter.setEncoding(cacheWriter.getEncoding());
              bsWriter.setLocale(cacheWriter.getLocale());
              bsWriter.setMimetype(cacheWriter.getMimetype());
              bsWriter.putContent(cacheWriter.getReader());
            }
          });

      return cacheWriter;
    } else {
      // No need to invalidate the cache for this content URL, since a content URL
      // is only ever written to once.
      return backingStore.getWriter(context);
    }
  }
Example #2
0
  @Override
  public ContentWriter getWriter(final String url) {
    // Get a writer to a cache file.
    final File cacheFile = createCacheFile();
    ContentWriter writer = new FileContentWriter(cacheFile, url, null);

    // Attach a listener to populate the in-memory store when done writing.
    writer.addListener(
        new ContentStreamListener() {
          @Override
          public void contentStreamClosed() throws ContentIOException {
            recordCacheEntries(url, cacheFile);
          }
        });

    return writer;
  }