Tiddo
Tiddo

Reputation: 6544

PHP caching dynamically constructed files

I am currently working on a small personal framework for web applications, based on the MVC pattern. In this framework some pages and templates are dynamically constructed from multiple files. However, especially these templates won't change often, so I want to create some form of caching. Ideally I only want to update the cached files when the original source files are changed, and I want to update the cached files on the first request after one of the source files is changed. But since 1 cache file is constructed from multiple source files, I need some way to know which source files belongs to a cache file, so I know which files I need to check for updates.

I came up with the idea to either use a table in a database or a separate file which saves that information. However, this requires some extra overhead on each page request, since I'll have to read one more file or I'll have to do some database IO. Are there any other techniques I can use to have as little overhead as possible?

ps. Caching isn't really needed since I'll only use it for a few small websites on a server which is far too powerful for these websites. However, I think it's a good practice for me to become more used to caching techniques.

Upvotes: 0

Views: 105

Answers (1)

Len
Len

Reputation: 542

Maybe look into PHP APC, you can create SHA1 hashes for your templates and store them in the cache with long expiration times. You can create flags in the cache when things change, and retrieve the documents from the cache vs the file system.

Upvotes: 0

Related Questions