def getRAMCacheKey(request, etag=None, lastModified=None):
    """Calculate the cache key for pages cached in RAM.

    ``etag`` is a unique etag string.

    ``lastModified`` is a datetime object giving the last=modified
     date for the resource.

    The cache key is a combination of the resource's URL, the etag,
    and the last-modified date. Both the etag and last=modified are
    optional but in most cases that are worth caching in RAM, the etag
    is needed to ensure the key changes when the resource view changes.
    """
    resourceKey = '{0}{1}?{2}'.format(request.get('SERVER_URL', ''),
        request.get('PATH_INFO', ''), request.get('QUERY_STRING', ''))
    if etag:
        resourceKey = '|' + etag + '||' + resourceKey
    if lastModified:
        resourceKey = '|' + str(lastModified) + '||' + resourceKey
    return resourceKey
