mercurial/HGCachedFileData.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 25 Jan 2013 20:10:10 +0000
changeset 203 85d2f90dc053
parent 180 7b70d26f28da
child 210 54a73fa50d40
permissions -rw-r--r--
Performance improvement: cache heads and branches. Cache heads and branches, The cache is invalidated repository changesets changes, Technically, .hg/00changesets.i file is monitored for a change (timestamp & size)

"{ Package: 'stx:libscm/mercurial' }"

Object subclass:#HGCachedFileData
	instanceVariableNames:'file timestamp size data reader'
	classVariableNames:''
	poolDictionaries:''
	category:'SCM-Mercurial-Internal'
!


!HGCachedFileData class methodsFor:'instance creation'!

on: file reader: reader
    ^self new setFile: file reader: reader

    "Created: / 14-01-2013 / 16:27:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGCachedFileData methodsFor:'accessing'!

value
    | fmtime fsize |
    fmtime := file modificationTime.
    fsize := file fileSize.

    (data notNil and:[timestamp notNil]) and:[
        (fmtime <= timestamp 
            and:[fsize = size]) ifTrue:[ ^ data ].
    ].
    data := reader valueWithOptionalArgument: data.
    timestamp := fmtime.
    size := fsize.
    ^data

    "Created: / 14-01-2013 / 16:25:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 25-01-2013 / 18:46:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGCachedFileData methodsFor:'initialization'!

flush
    data := timestamp := size := nil.

    "Created: / 14-01-2013 / 16:26:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

setData: anObject
    data := anObject

    "Created: / 25-01-2013 / 18:52:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

setFile:fileArg reader:readerArg 
    file := fileArg.
    reader := readerArg.

    "Created: / 14-01-2013 / 16:20:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGCachedFileData class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
! !