001 /**
002 * Copyright (C) 2009-2011 the original author or authors.
003 * See the notice.md file distributed with this work for additional
004 * information regarding copyright ownership.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package org.fusesource.restygwt.client.dispatcher;
020
021 import org.fusesource.restygwt.client.cache.CacheKey;
022 import org.fusesource.restygwt.client.cache.QueueableCacheStorage;
023 import org.fusesource.restygwt.client.cache.UrlCacheKey;
024 import org.fusesource.restygwt.client.callback.CallbackFactory;
025
026 import com.google.gwt.http.client.RequestBuilder;
027
028 /**
029 * using a different caching 'algorithm' obeying the restful paradigm, i.e.
030 * the cache respects the lifecycle of a restful resource:
031 * <li>POST /model : will get the user responds into the cache using the location header for the key</li>
032 * <li>GET /model/{id} : will use the cached responds from cache if present</li>
033 * <li>PUT /model/{id} : will put the responds from the server into the cache. a conflict will delete the cache entry to allow
034 * a get to retrieve the up to date date</li>
035 * <li>DELETE /model/{id} : will also delete the resource in the cache</li>
036 *
037 * @author <a href="blog.mkristian.tk">Kristian</a>
038 */
039 public class RestfulCachingDispatcherFilter extends CachingDispatcherFilter {
040
041 public RestfulCachingDispatcherFilter(QueueableCacheStorage cacheStorage,
042 CallbackFactory cf) {
043 super(cacheStorage, cf);
044 }
045
046 protected CacheKey cacheKey(RequestBuilder builder){
047 if (RequestBuilder.GET.toString().equalsIgnoreCase(builder.getHTTPMethod())){
048 return new UrlCacheKey(builder);
049 }
050 else {
051 return null;
052 }
053 }
054 }