Emerjoin / Hi-Framework-features

Java EE Framework
5 stars 1 forks source link

Web tuning 2.0 - static assets caching #124

Closed Emerjoin closed 7 years ago

Emerjoin commented 7 years ago

Defining static caching

 <web-tuning>

        <webroot>
            <folders-fixed-caching>
                <!--This will cache all assets under photos/ directory for 1 year-->
                <enabled age-unit="YEARS" age="1" folder-path="photos/*"/>

                <!--This will cache all assets under photos/customers directory-->
                <enabled age-unit="YEARS" age="1" folder-path="photos/customers/*"/>

            </folders-fixed-caching>
        </webroot>

    </web-tuning>

Validating caching algorithm example

URL : webroot/photos/mega/banners/huge.png

  1. Check photos/mega/sub/another/banners/
  2. Check photos/mega/sub/another/banners/*
  3. Check photos/mega/sub/another/*
  4. Check photos/mega/sub/*
  5. Check photos/mega/*
  6. Check photos/*

Performing this validation for every single asset will add some significant overhead even to assets that aren't cached. To reduce the overhead, a hinting method must be implemented

 <web-tunning>

        <webroot>
            <folders-fixed-caching>
                <!--This will cache all assets under photos/ directory recursively for 1 year-->
                <enabled age-unit="YEARS" age="1" folder-path="photos/*"/>

                <!--This will cache all assets under photos/customers directory recursively-->
                <enabled age-unit="YEARS" age="1" folder-path="photos/customers/*"/>
                 <!--This will tell the Assets requests handler to not worry about files under photos/whatever/path/ recursively because they arent cached-->
                <no-cache-hint path="photos/whatever/path/*"></no-cache-hint>

                 <!--This will tell the Assets requests handler to not worry about files under photos/whatever/path/ (not recursively) because they arent cached-->
                <no-cache-hint path="photos/whatever/path/"></no-cache-hint>
            </folders-fixed-caching>
        </webroot>

    </web-tunning>

Validating caching algorithm example (considering hints)

URL : webroot/photos/mega/banners/huge.png

  1. _Check no-cache hint for__ photos/*
  2. _Check no-cache hint for__ photos/mega/banners/
  3. Check photos/mega/sub/another/banners/
  4. Check photos/mega/sub/another/banners/*
  5. Check photos/mega/sub/another/*
  6. Check photos/mega/sub/*
  7. Check photos/mega/*
  8. Check photos/*