22 Mayıs 2013

XML Cache Refresh Problem

ile Yunus KALDIRIM

XML dosyasının swf dosyalarından çağrıldığı durumlarda browser özelliklerine bağlı olarak dosya yenilenmemekte ve temporary internet files klasörüne birkez alınarak cachten okunmaktadır. Bu xml dosyaları ile ilgili dünya üzerindeki en temel problemdir. Burada apache tomcat sunucu üzerinde xml ve veya arzu edilen diğer dosya türlerine kaynağında expire zamanı atama anlatılmaktadır. Bu konuda çok fazla araştırma yaptım ve sizlere umarım kolaylık olur :)

Symptoms:

  • When load xml files by URLLoaders, they are often cached by the browsers and do flash is unable to display the updated data.
  • XML cache problem
  • Prevent xml caching
  • Clear xml cache swf flash file
  • SAP Xcelsius xml cache refresh problem
  • Xcelsius caches an XML map
  • Need browser to stop caching XML file
  • Problems with cache – system returns always the same XML
  • How to load the latest XML file to solve the cache problem
  • Problem on refreshing with XML Data Connection

Solution:

1: Using now , date time in url .You can find this solution in everywhere. This is not the best but seems working.I don’t suggest because these files are stored in temporary folder of browser.

eg: xmlfile.xml?stopcaching=<%=NOW()%> or http://localhost/file.xml?v=12032012140023

2: Disabling cache meta tags in html header. This is not effected to xml cache problem .But you can see html is not being cached.You can find below tags in forums. But these are not stopping xml caching.

<meta http-equiv=”pragma” content=”no-cache”/>
<meta http-equiv=”expires” content=”0″/>
<meta http-equiv=”cache-control” content=”no-cache”/>

3: Change browser history caching settings. This is effected to xml refresh problem. But you are not able to set any users’ browser.Maybe only your’s. It’s their computer setting and there is noway to set their browser config remotely.

4:Some suggestions on php. I don’t know exactly how to use php to stop caching xml files. Maybe applicable.

5:My solution which seem best is adding some filter parameters to Apache Tomcat 6.x version. (If you are using IIS, I offer you to find same solution)

Here is steps:

  • Download cache filter file(cachefilter-2.0.jar ) from http://code.google.com/p/cache-filter/wiki/CacheFilter
  • Stop your Tomcat server
  • Copy the cachefilter.jar file to [TOMCAT_HOME]/webapps/xxxyourapp/WEB-INF/lib
  • Modify the [TOMCAT_HOME]/webapps/xxxyourapp/WEB-INF/web.xml file
  • Add this section anywhere you want within the web.xml file
  • Of course at the end restart Tomcat server
<filter>
    <filter-name>xmlCache</filter-name>
    <filter-class>com.samaxes.filter.CacheFilter</filter-class>
    <init-param>
        <param-name>private</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>expirationTime</param-name>
        <param-value>0</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>xmlCache</filter-name>
    <url-pattern>*.xml</url-pattern>
</filter-mapping>