Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
add LastModified header, allow I/O free caching.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Newson committed Mar 14, 2011
1 parent 33f6f65 commit 04968ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
* compaction
* parallel reads
* round-robin writing
* LastModified instead of Version
* DELETE support
* efficient range requests
* remember Content-Type
Expand Down
2 changes: 1 addition & 1 deletion src/monic_file.erl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ init(Path) ->
handle_call({start_writing, Key, Cookie, Size}, _From,
#state{main_fd=MainFd, write_pos=Pos, writer=nil}=State) ->
Ref = make_ref(),
LastModified = now(),
LastModified = erlang:universaltime(),
Header = #header{cookie=Cookie, key=Key, size=Size, last_modified=LastModified},
Index = #index{cookie=Cookie, key=Key, location=Pos, size=Size, last_modified=LastModified},
case monic_utils:pwrite_term(MainFd, Pos, Header) of
Expand Down
17 changes: 17 additions & 0 deletions src/monic_item_resource.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
allowed_methods/2,
content_types_accepted/2,
content_types_provided/2,
last_modified/2,
resource_exists/2,
valid_entity_length/2]).
-export([get_item/2, put_item/2]).
Expand All @@ -38,6 +39,22 @@ content_types_provided(ReqData, Context) ->
content_types_accepted(ReqData, Context) ->
{[{?ITEM_MIME_TYPE, put_item}], ReqData, Context}.

last_modified(ReqData, Context) ->
Key = wrq:path_info(key, ReqData),
Cookie = list_to_integer(wrq:path_info(cookie, ReqData)),
LastModified1 = case monic_utils:open(ReqData, Context) of
{ok, Pid} ->
case monic_file:info(Pid, Key, Cookie) of
{ok, {_, _, LastModified}} ->
LastModified;
{error, not_found} ->
undefined
end;
_ ->
undefined
end,
{LastModified1, ReqData, Context}.

resource_exists(ReqData, Context) ->
Key = wrq:path_info(key, ReqData),
Cookie = list_to_integer(wrq:path_info(cookie, ReqData)),
Expand Down

0 comments on commit 04968ac

Please sign in to comment.