Lookup Pattern: Incremental persistent cache updates

Published Mar 25 2019 02:18 PM 198 Views
Not applicable
First published on MSDN on Nov 23, 2008

The Cache Transform isn't currently able to update (i.e. append to) an existing persistent cache file. This pattern presents a way to incrementally build up your lookup cache if your data flow process is responsible for adding new rows to your reference table. For an alternative approach, please see the Other Resources section at the end of this post.


The process is split up across multiple packages. Because a Cache Connection Manager reads its cache file once, and keeps the cache in memory until package execution is complete, you can't read and update a cache file in the same package.


Control Package


This is the control package which uses a script task to check if the cache file already exists. If it doesn't, it executes the "Create Cache" package. Once the cache is there, the main data flow package which performs your general ETL logic is executed. The "Data Flow" package will write out any new rows for the reference cache to a temporary file, and update a variable in the control package to indicate how many rows were written out. The parent checks if any rows were written, and if so, runs the "Update Cache" package to update the persistent cache file



Create Cache


The cache creation package reads the source reference data, and then writes it to two separate locations. First it uses the Cache Transform to create a persistent cache, and then it writes the same data out to a RAW file. This RAW file will be incrementally updated by the Data Flow package to store the latest data for our reference set.



Data Flow


In the main ETL package, we use a key generation pattern to generate and insert new values into our reference table. Instead of rejoining the main flow right away, we multicast it out to a Row Count, followed by a RAW File Destination.


The Row Count writes to a local variable. After this data flow, we'll use a script task to copy this variable's value over to a variable in the parent package. You can see Jamie Thomson's post for more about how this works.


The RAW File Destination is able to append to an existing RAW File. Here we use it to add the new rows to the "incremental update" file we created in the "Create Cache" package.



Update Cache


If the main ETL package wrote any new rows to the incremental update RAW file, the control package will run the Update Cache package. This package simply reads the incremental update file (which will contain the entire cache, since it's simply being appended to each time), and recreate the cache file.



The sample packages used in this post can be downloaded from my SkyDrive share.



Other Resources


%3CLINGO-SUB%20id%3D%22lingo-sub-387514%22%20slang%3D%22en-US%22%3ELookup%20Pattern%3A%20Incremental%20persistent%20cache%20updates%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-387514%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Nov%2023%2C%202008%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EThe%20%3CA%20href%3D%22http%3A%2F%2Fblogs.msdn.com%2Fmattm%2Farchive%2F2008%2F11%2F22%2Flookup-using-the-cache-connection-manager.aspx%22%20mce_href%3D%22http%3A%2F%2Fblogs.msdn.com%2Fmattm%2Farchive%2F2008%2F11%2F22%2Flookup-using-the-cache-connection-manager.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20Cache%20Transform%20%3C%2FA%3E%20isn't%20currently%20able%20to%20update%20(i.e.%20append%20to)%20an%20existing%20persistent%20cache%20file.%20This%20pattern%20presents%20a%20way%20to%20incrementally%20build%20up%20your%20lookup%20cache%20if%20your%20data%20flow%20process%20is%20responsible%20for%20adding%20new%20rows%20to%20your%20reference%20table.%20For%20an%20alternative%20approach%2C%20please%20see%20the%20Other%20Resources%20section%20at%20the%20end%20of%20this%20post.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EThe%20process%20is%20split%20up%20across%20multiple%20packages.%20Because%20a%20Cache%20Connection%20Manager%20reads%20its%20cache%20file%20once%2C%20and%20keeps%20the%20cache%20in%20memory%20until%20package%20execution%20is%20complete%2C%20you%20can't%20read%20and%20update%20a%20cache%20file%20in%20the%20same%20package.%3C%2FP%3E%3CBR%20%2F%3E%3CH3%20id%3D%22toc-hId-1484300387%22%20id%3D%22toc-hId-1625385818%22%3EControl%20Package%3C%2FH3%3E%3CBR%20%2F%3E%3CP%3EThis%20is%20the%20control%20package%20which%20uses%20a%20script%20task%20to%20check%20if%20the%20cache%20file%20already%20exists.%20If%20it%20doesn't%2C%20it%20executes%20the%20%22Create%20Cache%22%20package.%20Once%20the%20cache%20is%20there%2C%20the%20main%20data%20flow%20package%20which%20performs%20your%20general%20ETL%20logic%20is%20executed.%20The%20%22Data%20Flow%22%20package%20will%20write%20out%20any%20new%20rows%20for%20the%20reference%20cache%20to%20a%20temporary%20file%2C%20and%20update%20a%20variable%20in%20the%20control%20package%20to%20indicate%20how%20many%20rows%20were%20written%20out.%20The%20parent%20checks%20if%20any%20rows%20were%20written%2C%20and%20if%20so%2C%20runs%20the%20%22Update%20Cache%22%20package%20to%20update%20the%20persistent%20cache%20file%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F99423i697E18E1A4A9AED1%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CH3%20id%3D%22toc-hId--1067856574%22%20id%3D%22toc-hId--926771143%22%3ECreate%20Cache%3C%2FH3%3E%3CBR%20%2F%3E%3CP%3EThe%20cache%20creation%20package%20reads%20the%20source%20reference%20data%2C%20and%20then%20writes%20it%20to%20two%20separate%20locations.%20First%20it%20uses%20the%20Cache%20Transform%20to%20create%20a%20persistent%20cache%2C%20and%20then%20it%20writes%20the%20same%20data%20out%20to%20a%20RAW%20file.%20This%20RAW%20file%20will%20be%20incrementally%20updated%20by%20the%20Data%20Flow%20package%20to%20store%20the%20latest%20data%20for%20our%20reference%20set.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F99424i3A34F5645423BE7D%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CH3%20id%3D%22toc-hId-674953761%22%20id%3D%22toc-hId-816039192%22%3EData%20Flow%3C%2FH3%3E%3CBR%20%2F%3E%3CP%3EIn%20the%20main%20ETL%20package%2C%20we%20use%20a%20%3CA%20href%3D%22http%3A%2F%2Fblogs.msdn.com%2Fmattm%2Farchive%2F2008%2F11%2F22%2Flookup-pattern-key-generation.aspx%22%20mce_href%3D%22http%3A%2F%2Fblogs.msdn.com%2Fmattm%2Farchive%2F2008%2F11%2F22%2Flookup-pattern-key-generation.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20key%20generation%20pattern%20%3C%2FA%3E%20to%20generate%20and%20insert%20new%20values%20into%20our%20reference%20table.%20Instead%20of%20rejoining%20the%20main%20flow%20right%20away%2C%20we%20multicast%20it%20out%20to%20a%20Row%20Count%2C%20followed%20by%20a%20RAW%20File%20Destination.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EThe%20Row%20Count%20writes%20to%20a%20local%20variable.%20After%20this%20data%20flow%2C%20we'll%20use%20a%20script%20task%20to%20copy%20this%20variable's%20value%20over%20to%20a%20variable%20in%20the%20parent%20package.%20You%20can%20see%20%3CA%20href%3D%22http%3A%2F%2Fblogs.conchango.com%2Fjamiethomson%2Farchive%2F2005%2F09%2F01%2F2096.aspx%22%20mce_href%3D%22http%3A%2F%2Fblogs.conchango.com%2Fjamiethomson%2Farchive%2F2005%2F09%2F01%2F2096.aspx%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20Jamie%20Thomson's%20post%20%3C%2FA%3E%20for%20more%20about%20how%20this%20works.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EThe%20RAW%20File%20Destination%20is%20able%20to%20append%20to%20an%20existing%20RAW%20File.%20Here%20we%20use%20it%20to%20add%20the%20new%20rows%20to%20the%20%22incremental%20update%22%20file%20we%20created%20in%20the%20%22Create%20Cache%22%20package.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F99425iBB72710E3B96552E%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CH3%20id%3D%22toc-hId--1877203200%22%20id%3D%22toc-hId--1736117769%22%3EUpdate%20Cache%3C%2FH3%3E%3CBR%20%2F%3E%3CP%3EIf%20the%20main%20ETL%20package%20wrote%20any%20new%20rows%20to%20the%20incremental%20update%20RAW%20file%2C%20the%20control%20package%20will%20run%20the%20Update%20Cache%20package.%20This%20package%20simply%20reads%20the%20incremental%20update%20file%20(which%20will%20contain%20the%20entire%20cache%2C%20since%20it's%20simply%20being%20appended%20to%20each%20time)%2C%20and%20recreate%20the%20cache%20file.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F99426iEFCDD9D9AEE63376%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EThe%20sample%20packages%20used%20in%20this%20post%20can%20be%20downloaded%20from%20my%20SkyDrive%20share.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CIFRAME%20frameborder%3D%220%22%20src%3D%22http%3A%2F%2Fcid-2aeb3aa8bb4bd9fd.skydrive.live.com%2Fembedrowdetail.aspx%2FPublic%2FIncrementalCacheUpdate.zip%22%3E%20%3C%2FIFRAME%3E%3C%2FP%3E%3CBR%20%2F%3E%3CH3%20id%3D%22toc-hId--134392865%22%20id%3D%22toc-hId-6692566%22%3EOther%20Resources%3C%2FH3%3E%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3EJohn%20Welch%20has%20an%20%3CA%20href%3D%22http%3A%2F%2Fagilebi.com%2Fcs%2Fblogs%2Fjwelch%2Farchive%2F2008%2F05%2F06%2Fssis-2008-incrementally-updating-the-lookup-cache-file.aspx%22%20mce_href%3D%22http%3A%2F%2Fagilebi.com%2Fcs%2Fblogs%2Fjwelch%2Farchive%2F2008%2F05%2F06%2Fssis-2008-incrementally-updating-the-lookup-cache-file.aspx%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20alternative%20approach%20to%20incremental%20updates%3C%2FA%3E%3C%2FLI%3E%0A%20%20%3C%2FUL%3E%0A%20%0A%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-387514%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Nov%2023%2C%202008%20The%20Cache%20Transform%20isn't%20currently%20able%20to%20update%20(i.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-387514%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Elookup%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Mar 25 2019 02:18 PM
Updated by: