Post a Cache class personal useful --by abbish

xiaoxiao2021-03-06  63

Class

cache

{Var

$ Cachedirectory

VAR

$ Cachedure

=

3600

VAR

$ cachefilename

Function

cache

(

$ Cachedure

=

3600

,

$ Cachedirectory

=

'./cache'

) {

$ THIS

->

Cachedure

=

0

;

$ THIS

->

Cachefilename

=

'' '

;

$ THIS

->

Cachedirectory

=

'.'. '

;

$ THIS

->

Updatecache

(

$ Cachedure

,

$ Cachedirectory

} Function

_MAKECACHEFOLDER

() {If (!

IS_DIR

(

$ THIS

->

Cachedirectory

)) {

$ TEMP

=

EXPLODE

(

'/'

,

$ THIS

->

Cachedirectory

);

$ CUR_DIR

=

'' '

; For

$ I

=

0

;

$ I

<

count

(

$ TEMP

);

$ I

) {

$ CUR_DIR

=

$ TEMP

[

$ I

].

'/'

; If (!

IS_DIR

(

$ CUR_DIR

)) {IF (@

Mkdir

(

$ CUR_DIR

,

777

) &&

$ CUR_DIR

! =

GetCWD

()) {

$ THIS

->

_Writefile

(

$ CUR_DIR

.

'.htaccess'

,

'Deny from all'

);

$ THIS

->

_Writefile

(

$ CUR_DIR

.

'Index.html'

,

'' '

);}}}}}

GetCacheFileName

() {RETURN

$ THIS

->

Cachefilename

} Function

_SETCACHEFILENAME

(

$ contents

) {

$ THIS

->

Cachefilename

=

$ THIS

->

Cachedirectory

.

'/'

.

MD5

(

$ contents

).

'.TXT'

} Function

Incache

(

$ contents

,

$ STY

=

'' '

) {

$ THIS

->

_SETCACHEFILENAME

(

$ contents

); If

$ STY

==

1

) {RETURN

FILE_EXISTS

(

$ THIS

->

Cachefilename);} else {ix

FILE_EXISTS

(

$ THIS

->

Cachefilename

)) {

$ TIM

=

Filemtime

(

$ THIS

->

Cachefilename

); IF

Time

() -

$ TIM

)>

$ THIS

->

Cachedure

) {RETURN

False

Else {RETURN

True

}} Else {return

False

}}} Function

READCACHE

() {

$ contents

=

'' '

;

$ fp

= @

Fopen

(

$ THIS

->

Cachefilename

,

'r'

); If

$ fp

) {While

Feof

(

$ fp

))

$ contents

=

FREAD

(

$ fp

,

4096

);

Fclose

(

$ fp

} Return

$ contents

} Function

Updatecache

(

$ Cachedure

=

3600

,

$ Cachefolder

=

'./cache'

) {

$ THIS

->

Cachedure

=

$ Cachedure

;

$ THIS

->

Cachedirectory

=

$ Cachefolder

;

$ THIS

->

_MAKECACHEFOLDER

();} Function

SaveIncache

(

$ contents

,

$ FileName

=

'' '

) {IF

TRIM

(

$ FileName

) ==

'' '

)

$ FileName

=

$ contents

; IF

$ THIS

->

Incache

(

$ FileName

,

1

)) {IF

Time

() -

Filemtime

(

$ THIS

->

Cachefilename

)))

$ THIS

->

Cachedure

) {@

Unlink

(

$ THIS

->

Cachefilename

}}

$ THIS

->

_Writefile

(

$ THIS

->

Cachefilename

,

$ contents

} Function

_Writefile

(

$ FileName

,

$ contents

) {If (! File_exists

(

$ FileName

)) {

$ fp

= @

Fopen

(

$ FileName

,

'W'

); If

$ fp

) {

FPUTS

(

$ fp

,

$ contents

);

Fclose

(

$ fp

}} Else {

Unlink

(

$ FileName

);

$ fp

= @

Fopen

(

$ FileName

,

'W'

); If

$ fp

) {

FPUTS

(

$ fp

,

$ contents

);

Fclose

(

$ fp

}}}}

?>

# Www.openshow.org # Seeking cooperation Open Source Technology Website # Contact QQ: 47641788Class Abbish {var $ usrname; var $ mywebsite; function abbish () {$ this-> username = "abbish"; $ this-> mywebsite = array ( "DOWNV" => "http://www.downv.com", "openshow" => "http://www.openshow", "more" => "...");} function Output () {Print $ this-> UserName; Print_R $ this-> mywebsite;}}}

转载请注明原文地址:https://www.9cbs.com/read-118666.html

New Post(0)