RE: Publication date

"ghislain\.cussonneau" <[email protected]>
Newsgroups gmane.comp.cms.jahia.template
Message-ID <[email protected]>
Ok !

I've done that and everything goes well ! For your interest, the following codes are the solution I've use (in order templates adding code / patch on jahia / apache conf).

I've put the new HtmlCacheEntry in webapps/jahia/WEB-INF/classes directory, modify the jahia.properties to add the property "readonlyserver" and restart the server.

TEMPLATES

Here is the code I had in header.inc (after the include of declarations.inc) :
<%
// Definition des headers en fonction des droits des utilisateurs
// Si on est en anonyme ou que le serveur est utilisé en lecture uniquement --> utilisation du cache Apache
if (!jData.gui().isLogged() || bIsReadonlyServer)
{
  int iCacheMaxExpire = 24*3600; // 24 heures max pour cache Apache
  // Get the language code
  String curLanguageCode = LanguageCodeConverters.localeToLanguageTag(jParams.getLocale());
  // Extract the workflow state out of the parameters bean
  int workflowState = jParams.getEntryLoadRequest().getWorkflowState();
  // Get the HTML cache instance
  HtmlCache htmlCache = CacheFactory.getHtmlCache();
  // Get the CacheEntry
  String entryKey = htmlCache.computeEntryKey(Integer.toString(jParams.getPageID()),
  jParams.getUser().getUsername(), curLanguageCode, workflowState, jParams.getUserAgent());
  Date dLastModifiedCacheDate = new Date();
  try {
    CacheEntry cacheEntry = (CacheEntry)htmlCache.getCacheEntry(entryKey);
    HtmlCacheEntry htmlEntry = (HtmlCacheEntry) cacheEntry.getObject();
    dLastModifiedCacheDate.setTime(htmlEntry.getContentTimestamp());
  } catch(Exception e) {}
  Date dExpires = new Date();
  dExpires.setTime(dLastModifiedCacheDate.getTime() + iCacheMaxExpire);
  logger.debug("Header Expires = " + getDateAsRFC822String(dExpires));
  logger.debug("Header Last-Modified = " + getDateAsRFC822String(dLastModifiedCacheDate));
  logger.debug("Header Cache-Control = " + "max-age=" + iCacheMaxExpire + ", must-revalidate");
  response.addHeader("Expires", getDateAsRFC822String(dExpires));
  response.addHeader("Last-Modified", getDateAsRFC822String(dLastModifiedCacheDate));
  response.addHeader("Cache-Control", "max-age=" + iCacheMaxExpire + ", must-revalidate");
}
// Autrement --> pas de cache Apache
else 
{
  Date dExpiresAbsolute = new Date();
  dExpiresAbsolute.setTime(dExpiresAbsolute.getTime() + 24*3600);
  logger.debug("Header Cache-Control = no-cache");
  logger.debug("Header Pragma = No-Cache");
  logger.debug("Header ExpiresAbsolute = " + getDateAsRFC822String(dExpiresAbsolute));
  logger.debug("Header Expires = -1");
  response.addHeader("Cache-Control", "no-cache");
  response.addHeader("Pragma", "No-Cache");
  response.addHeader("ExpiresAbsolute", getDateAsRFC822String(dExpiresAbsolute));
  response.addHeader("Expires", "-1");
}
%>
Here is the code I had in declarations.inc :

private static PropertiesManager properties = new PropertiesManager(Jahia.getJahiaPropertiesFileName ());
private boolean bIsReadonlyServer = "true".equals(properties.getProperty("readonlyserver"));

public static SimpleDateFormat RFC822DATEFORMAT = new SimpleDateFormat("EEE', 'dd' 'MMM' 'yyyy' 'HH:mm:ss' 'Z", Locale.US);
public static String getDateAsRFC822String(Date date)
{
  return RFC822DATEFORMAT.format(date);
}

PATCH JAHIA 4.0.6

Here is my personnal org.jahia.services.cache.HtmlCacheEntry (in red the code I've had) :

public class HtmlCacheEntry implements Serializable {

    /** the HTML body content. */
    private String contentBody = "";

    /** the HTML content type. */
    private String contentType = "";

    /** the date of HTMLCacheEntry creation / update **/
    private long contentTimestamp = -1;

    public HtmlCacheEntry (String contentBody) {
        init (contentBody, null, new Date().getTime());
    }

    public HtmlCacheEntry (String contentBody, String contentType) {
        init (contentBody, contentType, new Date().getTime());
    }

    private void init (String contentBody, String contentType, long contentTimestamp) {
        if (contentBody != null)
            this.contentBody = contentBody;
        if (contentType != null)
            this.contentType = contentType;
        
        this.contentTimestamp = contentTimestamp;
        
    }

    final public String getContentType() {
        return contentType;
    }

    final public void setContentType (String contentType) {
        this.contentType = contentType;
        this.contentTimestamp = new Date().getTime();
    }

    final public String getContentBody() {
        return contentBody;
    }

    final public void setContentBody (String contentBody) {
        this.contentBody = contentBody;
        this.contentTimestamp = new Date().getTime();
    }

   final public long getContentTimestamp() {
       return contentTimestamp;
   }
}

Then in Apache, I've had a new virtual site declaration for my site

<VirtualHost *:80>
  ServerName www.mysite.mydomain.fr
  # Logging access
  CustomLog "|/apache/2.0.54/bin/rotatelogs /apache/logs/jahiaconsult_access_mysitekey_log.%Y-%m-%d-%H_%M_%S.log 86400" common
  # Redirections
  Redirect /index.html http://www.mysite.mydomain.fr/jahia/Jahia/site/mysitekey
  DocumentRoot /apache/2.0.54/htdocs
  RewriteEngine On
  RewriteRule /favicon.ico - [F]
  RewriteRule (.*)/op(.*)$ http://www.mysite.mydomain.edit.fr/jahia/Jahia/engineName/login/site/mysitekey
  RewriteRule ^/jahia/administration(.*)$ http://www.mysite.mydomain.edit.fr/jahia/administration
  ProxyPass /jahia/Jahia/op !
  ProxyPass /jahia/Jahia/site/mysitekey/op !
  ProxyPass /jahia/administration !
  ProxyPass /jahia http://www.mysite.mydomain.fr:9080/jahia
  ProxyPassReverse /jahia http://www.mysite.mydomain.fr:9080/jahia
  # Gestion du Cache
  CacheRoot "/apache/2.0.54/proxy/www.mysite.mydomain.fr"
  CacheSize 50000
  CacheEnable disk /
  CacheGcInterval 0.25
  CacheMaxExpire 180
  CacheLastModifiedFactor 0.1
  CacheDefaultExpire 0.25
  CacheDirLength 2
  CacheDirLevels 3
  # Expire - by request
  ExpiresActive On
  ExpiresByType image/gif A86400
  ExpiresByType image/png A86400
  ExpiresByType image/jpeg A86400
  ExpiresByType text/css A86400
</VirtualHost>


Regards for your Help.

Ghislain CUSSONNEAU

DIRR/DPIL/CIS

CAP 44, Rue Marcel Sembat

44000 Nantes

02 51 84 48 80

Accédez au courrier électronique de La Poste : www.laposte.net ;
Jusqu'au 25 décembre, participez  au grand jeu du Calendrier de l'Avent et
 gagnez tous les jours de nombreux lots, + de 300 cadeaux en jeu !
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.