 
 		# Update generating flag
 		docpad.generating = false
+		docpad.generateEnded = new Date()
+
+		# Update caches
+		docpad.databaseCache = null
 		collection.each (file) ->
 			for url in file.get('urls')
 				docpad.filesByUrl[url] = file.cid
-		docpad.filesByUrlCache = docpad.filesByUrl
 
 		# Fire plugins
 		docpad.emitSync 'generateAfter', server:docpad.getServer(), (err) ->
 			return next(err)  if err
 
 			# Log generated
-			seconds = (new Date() - docpad.lastGenerate) / 1000
+			seconds = (docpad.generateEnded - docpad.generateStarted) / 1000
 			howMany =
 				if collection is database
 					"all #{collection.length}"

	# Get Files (will use live collections)
	getFiles: (query,sorting,paging) ->
		key = JSON.stringify({query,sorting,paging})
		result = @getCollection(key)
		unless result
			result = @getDatabase().findAllLive(query,sorting,paging)
			@setCollection(key, result)
		return result

	# Get another file's model based on a relative path
	getFile: (query,sorting,paging) ->
		result = @getDatabase().findOne(query,sorting,paging)
		return result

	# Get Files At Path
	getFilesAtPath: (path,sorting,paging) ->
		query = $or: [{relativePath: $startsWith: path}, {fullPath: $startsWith: path}]
		result = @getFiles(query,sorting,paging)
		return result

	# Get another file's model based on a relative path
	getFileAtPath: (path,sorting,paging) ->
		result = @getDatabase().fuzzyFindOne(path,sorting,paging)
		return result

	# Get a file by its url
	getFileByUrl: (url) ->
		result = @getDatabase().get(@filesByUrl[url])
		return result

	# Get a file by its selector
	getFileBySelector: (selector,opts) ->
		opts.collection ?= @getDatabase()
		result = collection.get(@filesBySelector[selector])
		unless result
			result = collection.fuzzyFindOne(selector)
			if result
				@filesBySelector[selector] = result.id
		return result


	# ---------------------------------

	serverMiddleware500: (err,req,res,next) =>
		# Prepare
		docpad = @
		database = docpad.getDatabaseCache()

		# Check
		return res.send(500)  unless database
