improve client side caching

This commit is contained in:
Sebastian Sdorra
2011-02-15 17:04:03 +01:00
parent 5c4ab6b77d
commit 95d1d206fb
6 changed files with 259 additions and 48 deletions

View File

@@ -263,22 +263,22 @@ public class Group implements ModelObject, Iterable<String>
{
int hash = 7;
hash = 29 * hash + ((this.creationDate != null)
hash = 73 * hash + ((this.creationDate != null)
? this.creationDate.hashCode()
: 0);
hash = 29 * hash + ((this.description != null)
hash = 73 * hash + ((this.description != null)
? this.description.hashCode()
: 0);
hash = 29 * hash + ((this.lastModified != null)
hash = 73 * hash + ((this.lastModified != null)
? this.lastModified.hashCode()
: 0);
hash = 29 * hash + ((this.members != null)
hash = 73 * hash + ((this.members != null)
? this.members.hashCode()
: 0);
hash = 29 * hash + ((this.name != null)
hash = 73 * hash + ((this.name != null)
? this.name.hashCode()
: 0);
hash = 29 * hash + ((this.type != null)
hash = 73 * hash + ((this.type != null)
? this.type.hashCode()
: 0);
@@ -371,6 +371,7 @@ public class Group implements ModelObject, Iterable<String>
*
* @return
*/
@Override
public Long getLastModified()
{
return lastModified;

View File

@@ -100,6 +100,75 @@ public class Permission implements Serializable
this.groupPermission = groupPermission;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param obj
*
* @return
*/
@Override
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final Permission other = (Permission) obj;
if (this.groupPermission != other.groupPermission)
{
return false;
}
if ((this.name == null)
? (other.name != null)
: !this.name.equals(other.name))
{
return false;
}
if (this.type != other.type)
{
return false;
}
return true;
}
/**
* Method description
*
*
* @return
*/
@Override
public int hashCode()
{
int hash = 7;
hash = 97 * hash + (this.groupPermission
? 1
: 0);
hash = 97 * hash + ((this.name != null)
? this.name.hashCode()
: 0);
hash = 97 * hash + ((this.type != null)
? this.type.hashCode()
: 0);
return hash;
}
//~--- get methods ----------------------------------------------------------
/**

View File

@@ -157,6 +157,145 @@ public class Repository implements ModelObject
repository.setUrl(url);
}
/**
* Method description
*
*
* @param obj
*
* @return
*/
@Override
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final Repository other = (Repository) obj;
if ((this.contact == null)
? (other.contact != null)
: !this.contact.equals(other.contact))
{
return false;
}
if ((this.creationDate != other.creationDate)
&& ((this.creationDate == null)
||!this.creationDate.equals(other.creationDate)))
{
return false;
}
if ((this.description == null)
? (other.description != null)
: !this.description.equals(other.description))
{
return false;
}
if ((this.id == null)
? (other.id != null)
: !this.id.equals(other.id))
{
return false;
}
if ((this.lastModified != other.lastModified)
&& ((this.lastModified == null)
||!this.lastModified.equals(other.lastModified)))
{
return false;
}
if ((this.name == null)
? (other.name != null)
: !this.name.equals(other.name))
{
return false;
}
if ((this.permissions != other.permissions)
&& ((this.permissions == null)
||!this.permissions.equals(other.permissions)))
{
return false;
}
if (this.publicReadable != other.publicReadable)
{
return false;
}
if ((this.type == null)
? (other.type != null)
: !this.type.equals(other.type))
{
return false;
}
if ((this.url == null)
? (other.url != null)
: !this.url.equals(other.url))
{
return false;
}
return true;
}
/**
* Method description
*
*
* @return
*/
@Override
public int hashCode()
{
int hash = 7;
hash = 61 * hash + ((this.contact != null)
? this.contact.hashCode()
: 0);
hash = 61 * hash + ((this.creationDate != null)
? this.creationDate.hashCode()
: 0);
hash = 61 * hash + ((this.description != null)
? this.description.hashCode()
: 0);
hash = 61 * hash + ((this.id != null)
? this.id.hashCode()
: 0);
hash = 61 * hash + ((this.lastModified != null)
? this.lastModified.hashCode()
: 0);
hash = 61 * hash + ((this.name != null)
? this.name.hashCode()
: 0);
hash = 61 * hash + ((this.permissions != null)
? this.permissions.hashCode()
: 0);
hash = 61 * hash + (this.publicReadable
? 1
: 0);
hash = 61 * hash + ((this.type != null)
? this.type.hashCode()
: 0);
hash = 61 * hash + ((this.url != null)
? this.url.hashCode()
: 0);
return hash;
}
/**
* Method description
*

View File

@@ -210,6 +210,18 @@ public class User implements Principal, ModelObject
final User other = (User) obj;
if (this.admin != other.admin)
{
return false;
}
if ((this.creationDate != other.creationDate)
&& ((this.creationDate == null)
||!this.creationDate.equals(other.creationDate)))
{
return false;
}
if ((this.displayName == null)
? (other.displayName != null)
: !this.displayName.equals(other.displayName))
@@ -217,6 +229,13 @@ public class User implements Principal, ModelObject
return false;
}
if ((this.lastModified != other.lastModified)
&& ((this.lastModified == null)
||!this.lastModified.equals(other.lastModified)))
{
return false;
}
if ((this.mail == null)
? (other.mail != null)
: !this.mail.equals(other.mail))
@@ -257,21 +276,30 @@ public class User implements Principal, ModelObject
@Override
public int hashCode()
{
int hash = 7;
int hash = 3;
hash = 79 * hash + ((this.displayName != null)
hash = 37 * hash + (this.admin
? 1
: 0);
hash = 37 * hash + ((this.creationDate != null)
? this.creationDate.hashCode()
: 0);
hash = 37 * hash + ((this.displayName != null)
? this.displayName.hashCode()
: 0);
hash = 79 * hash + ((this.mail != null)
hash = 37 * hash + ((this.lastModified != null)
? this.lastModified.hashCode()
: 0);
hash = 37 * hash + ((this.mail != null)
? this.mail.hashCode()
: 0);
hash = 79 * hash + ((this.name != null)
hash = 37 * hash + ((this.name != null)
? this.name.hashCode()
: 0);
hash = 79 * hash + ((this.password != null)
hash = 37 * hash + ((this.password != null)
? this.password.hashCode()
: 0);
hash = 79 * hash + ((this.type != null)
hash = 37 * hash + ((this.type != null)
? this.type.hashCode()
: 0);

View File

@@ -245,7 +245,7 @@ public abstract class AbstractManagerResource<T extends ModelObject,
}
else
{
response = createCacheResponse(request, item);
response = createCacheResponse(request, item, item);
}
return response;
@@ -267,7 +267,7 @@ public abstract class AbstractManagerResource<T extends ModelObject,
if (Util.isNotEmpty(items))
{
prepareForReturn(manager.getAll());
items = prepareForReturn(items);
}
Response response = null;
@@ -278,7 +278,7 @@ public abstract class AbstractManagerResource<T extends ModelObject,
}
else
{
response = createCacheResponse(request, items);
response = createCacheResponse(request, manager, items);
}
return response;
@@ -401,14 +401,17 @@ public abstract class AbstractManagerResource<T extends ModelObject,
*
*
* @param request
* @param timeItem
* @param item
* @param <I>
*
* @return
*/
private Response createCacheResponse(Request request, T item)
private <I> Response createCacheResponse(Request request,
LastModifiedAware timeItem, I item)
{
Response.ResponseBuilder builder = null;
Date lastModified = getLastModified(item);
Date lastModified = getLastModified(timeItem);
EntityTag e = new EntityTag(Integer.toString(item.hashCode()));
if (lastModified != null)
@@ -430,35 +433,6 @@ public abstract class AbstractManagerResource<T extends ModelObject,
return builder.build();
}
/**
* Method description
*
*
* @param request
* @param items
*
* @return
*/
private Response createCacheResponse(Request request, Collection<T> items)
{
Response.ResponseBuilder builder = null;
Date lastModified = getLastModified(manager);
if (lastModified != null)
{
builder = request.evaluatePreconditions(lastModified);
}
if (builder == null)
{
builder = Response.ok(items).lastModified(lastModified);
}
addCacheControl(builder);
return builder.build();
}
//~--- get methods ----------------------------------------------------------
/**
@@ -485,7 +459,7 @@ public abstract class AbstractManagerResource<T extends ModelObject,
//~--- fields ---------------------------------------------------------------
/** Field description */
protected int cacheMaxAge = 1;
protected int cacheMaxAge = 0;
/** Field description */
protected boolean disableCache = false;

View File

@@ -94,7 +94,7 @@ public class RepositoryResource
this.repositoryManager = repositoryManager;
this.securityContextProvider = securityContextProvider;
this.requestProvider = requestProvider;
setDisableCache(true);
setDisableCache(false);
}
//~--- methods --------------------------------------------------------------